#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, a, b;
  cin >> n >> q;
  vector<int> ar;
  for (int i = 0; i < q; i++) {
    cin >> a >> b;
    for (int j = a; j <= b; j++) {
      ar.push_back(j);
    }
  }
  sort(ar.begin(), ar.end());
  int len = ar.size();
  int dp[n + 1];
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    dp[i] = 0;
    for (int j = 0; j < len; j++) {
      if (i >= ar[j]) {
        dp[i] = dp[i] + dp[i - ar[j]];
      }
    }
  }
  cout << dp[n];
  return 0;
}
