S002-AC.cc 557 Bytes
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int r,c;
	double count = 0;
	char* row;

	cin >> r;
	cin >> c;

	if(r < 1 || c < 1)
	{
		cout << 0 << endl;
		return 0;
	}
	char num;
	int cont = 0;
	for(int i = 0; i< (r*c); i++) {
	cin >> num;cont += num-48;}
	/*for(int i = 0; i < r; i++)
	{
		row = new char[c];
		for(int j = 0; j < c; j++)
		{
			row[j] = 0;
		}
		cin >> row;
		if(cin.eof())
		{
			break;
		}
		for(int k = 0; k < c; k++)
		{
			count += row[k] - 48;
		}
		delete row;
	}*/
	cout << cont << endl;
	return 0;
}