#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
const int MOD = 1e9 + 7;
const ll ZER = 0;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> l(k), r(k);
  for (int i = 0; (i) < (int)(k); i++) cin >> l[i] >> r[i];
  vector<ll> dp(n + 1, 0);
  vector<ll> dpsum(n + 1, 0);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = (int)(2); (i) <= (int)(n - 1); i++) {
    for (int j = 0; (j) < (int)(k); j++) {
      ll li = max(ZER, i - r[j]), ri = max(ZER, i - l[j]);
      dp[i] += dpsum[ri] - dpsum[li - 1];
    }
    dpsum[i] += dpsum[i - 1] + dp[i];
  }
  cout << dp[n] << endl;
}
