#include <iostream>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
ll find_sum(vector<vector<ll>> a){
ll sum = 0;
for(ll i = 0; i < a.size(); i++)
for(ll j = 0; j < a[i].size(); j++)
if(i == j)
sum += a[i][j];
return sum;
}
signed main(){
ll n,m;
cin >> n >> m;
vector<vector<ll>> a(n);
for(ll i = 0; i < n; i++){
vector<ll> temp(m);
for(ll j = 0; j < m; j++)
cin >> temp[j];
a[i] = temp;
cout << find_sum(a);
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
ll find_sum(vector<vector<ll>> a){
ll sum = 0;
for(ll i = 0; i < a.size(); i++)
for(ll j = 0; j < a[i].size(); j++)
if(i == j)
sum += a[i][j];
return sum;
}
signed main(){
ll n,m;
cin >> n >> m;
vector<vector<ll>> a(n);
for(ll i = 0; i < n; i++){
vector<ll> temp(m);
for(ll j = 0; j < m; j++)
cin >> temp[j];
a[i] = temp;
}
cout << find_sum(a);
}