/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip> //setprecision
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#include <time.h> //clock
#define endl "\n";
using namespace std;

using PLL = pair<long long,long long>;
typedef tuple<int,int,int> TUP;
using P = pair<int,int>;
const long long INF = 3000000000000000001;
const int inf = 1001001001;
long long MOD = 1000000007;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M, long long mod) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % mod, M / 2,mod);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % mod;
    return res %= mod;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}
long long get_mod(long long res){
    if(res < 0) res += MOD;
    return res % MOD;
}



int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int H,W;cin >> H >> W;
    vector<vector<int>> ban(H,vector<int>(W));
    int mini = inf;
    int ans = 0;
    for(int i = 0;i<H;i++) for(int j = 0;j<W;j++) cin >> ban.at(i).at(j), mini = min(mini,ban.at(i).at(j));
    for(int i = 0;i<H;i++) for(int j = 0;j<W;j++) ans += ban.at(i).at(j)-mini;
    cout << ans << endl;
}

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

constexpr int kN = 73;

bitset<kN> bs[kN];
int n;
ll ans;
unordered_map<__int128, ll> ma;

void solve(bitset<kN> cur) {
	int id = cur._Find_first();
	__int128 val = 0;

	for (int i = n - 1; i >= id; i--) if (cur[i]) val |= __int128(1) << (n - 1 - i);
	if (ma.find(val) != ma.end()) {
		ans += ma[val];
		return ;
	}

	ll cur_ans = ans;
	ans++;
	for (int i = id; i < n; i = cur._Find_next(i)) solve(cur & bs[i]);

	ma[val] = ans - cur_ans;
	return ;
}

int main() {
	ll a, b; scanf("%lld%lld", &a, &b);
	n = b - a + 1;

	for (ll i = a; i <= b; i++) for (ll j = i + 1; j <= b; j++) if (__gcd(i, j) == 1) bs[i - a][j - a] = true;

	bitset<kN> cur;
	for (int i = 0; i < n; i++) cur[i] = true;
	solve(cur);

	printf("%lld\n", ans);
}
