#undef _GLIBCXX_DEBUG
// Problem: F - Rook on Grid
// Contest: AtCoder - Panasonic Programming Contest (AtCoder Beginner Contest 186)
// URL: https://atcoder.jp/contests/abc186/tasks/abc186_f
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

struct splitmix64_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}
 
	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
 
template <typename K, typename V, typename Hash = splitmix64_hash>
using hash_map = __gnu_pbds::gp_hash_table<K, V, Hash>;
 
template <typename K, typename Hash = splitmix64_hash>
using hash_set = hash_map<K, __gnu_pbds::null_type, Hash>;

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

int n, m, o;
int row[maxN], col[maxN];

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m >> o;
	RI(i, m) col[i] = -1;
	RI(i, n) row[i] = -1;
	REP(_, o) {
		int a, b; cin >> a >> b;
		if (row[a] == -1) row[a] = b - 1;
		else row[a] = min(row[a], b - 1);
		if (col[b] == -1) col[b] = a - 1;
		else col[b] = min(col[b], a - 1);
	}
	ll ans = 0;
	vector<pii> vec;
	if (row[1] == -1) row[1] = m;
	RI(i, m) {
		if (col[i] == -1) col[i] = n;
		if (i <= row[1]) {
			ans += col[i];
			vec.pb({col[i], i});
		} else {
			vec.pb({0, i});
		}
	}
	// cout << ans << endl;
	ordered_set s;
	sort(vec.begin(), vec.end());
	int cnt = 0;
	RI(i, col[1]) {
		while (cnt != m && vec[cnt].st < i) {
			s.insert(vec[cnt].nd);
			cnt++;
		}
		if (row[i] == -1) row[i] = m;
		// cout << i << " " << cnt << " " << row[i] << endl;
		ans += s.order_of_key(row[i] + 1);
	}
	cout << ans;
	return 0;
}
 

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
    ll X, N = 0;
    cin >> N >> X;
    vector<ll> A(N,0);
    for(ll i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    vector<ll> M(N, 0);
    for(ll i = 1; i < N; i++) {
        M.at(i - 1) = A.at(i)/A.at(i - 1) - 1;
    }

    ll t = X;
    vector<ll> x(N, 0);
    for(ll i = 1; i < N; i++) {
        ll memo = t%A.at(i);
        x.at(i - 1) = memo/A.at(i - 1);
        t -= memo;
    }
    ll p = 0, e = 1, l = 0;
    if(x.at(0)) {
        l = 1;
    }
    for(ll i = 1; i < N - 1; i++) {
        ll P = p, E = e, L = l;
        if(x.at(i) == M.at(i)) {
//             cout << "A" << endl;
            E = e;
            L = e + l;
        } else if(x.at(i) == 0) {
//             cout << "B" << endl;
            E = e + l;
            L = l;
        } else {
//             cout << "C" << endl;
            E = e + l;
            L = e + l;
        }
        p = P, e = E, l = L;
    }
    ll P = p, E = e, L = l;
    if(x.at(N - 1) == 0) {
//      cout << "B" << endl;
        E = e + l;
        L = 0;
    } else {
//      cout << "C" << endl;
        E = e + l;
        L = 0;
    }
    p = P, e = E, l = L;
    
    cout << e + l << endl;


    return 0;
}