#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const long long LINF = 1e18 + 14;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<int> dp(n * 2);
  vector<int> sums(n * 2);
  dp[n] = 1;
  sums[n] = 1;
  for (int i = n + 1; i < n * 2; i++) {
    for (int j = 0; j < k; j++) {
      dp[i] += sums[i - l[j]] - sums[i - r[j] - 1];
    }
    sums[i] = sums[i - 1] + dp[i];
  }
  cout << dp.back();
  return 0;
}
