#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define se second
#define sz size()
#define pb push_back()


map<ll,map<ll,ll>> dp;

ll f(ll n, ll m) {
    if(n==1&&m==1) return 1ll;

    if(n<m) swap(n,m);

    if(n%2==0) {
        if(dp[n/2][m]==0) dp[n/2][m]= f(n/2,m);
        dp[n][m] = 2ll*dp[n/2][m] + n*m;
        return dp[n][m];
    } else {
        if(dp[n/2][m]==0) dp[n/2][m] = f(n/2,m);
        if(dp[n/2+1][m]==0) dp[n/2+1][m] = f(n/2+1,m);
        dp[n][m] = dp[n/2][m] + dp[n/2+1][m] + n*m;
        return dp[n][m];
    }
}

int main(){
    ll n,m;
    cin>>n>>m;
    if(n==1 and m==1){
        cout<<0;
        return 0;
    }
    ll k=f(n,m);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++)
            cout<<dp[i][j]<<" ";
        cout<<"\n";
    }
    cout << k;
    return 0;
}
