#include <iostream>
#define forn(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
const int oo = 2e5+7;
int n, m;
ll gore, dole;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    forn (i, n) forn(j, m) {
        ll kurac;
        if (i == 0 && j == 0) cin >> gore;
        else if (i == n-1 && j == m-1) cin >> dole;
        else cin >> kurac;
    }
    cout << (dole ^ gore) << endl;
}