#include <iostream>

using namespace std;

int main()
{
    ll n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> a[i][j];
        }
    }
    if(n == 1 && m == 1){
        cout << "0" << endl;
    }
    else if(n == 1 && m == 2){
        ll rez = 0;
        ll mnozenje = 1;
        ll x = a[1][1];
        ll y = a[1][2];
        while(x > 0 || y > 0){
            if((x % 2) != (y % 2)){
                rez += mnozenje;
            }
            mnozenje *= 2;
            x /= 2;
            y /= 2;
        }
        cout << rez << endl;
    }
    else if(n == 2 && m == 1){
        ll rez = 0;
        ll mnozenje = 1;
        ll x = a[1][1];
        ll y = a[2][1];
        while(x > 0 || y > 0){
            if((x % 2) != (y % 2)){
                rez += mnozenje;
            }
            mnozenje *= 2;
            x /= 2;
            y /= 2;
        }
        cout << rez << endl;
    }
    else if(n == 2 && m == 2){
        
    }
    else{
        cout << "5" << endl;
    }
    return 0;
}