#include <bits/stdc++.h>
using namespace std;
long long int f(set<long long int> S, long long int N, long long int cnt) {
  if (N < 0)
    return cnt;
  else if (N == 0) {
    cnt++;
    return cnt;
  }
  for (auto x : S) {
    cnt = f(S, N - x, cnt);
  }
  return cnt;
}
int main() {
  long long int n, k;
  cin >> n;
  cin >> k;
  set<long long int> S;
  long long int l[k], r[k];
  for (int i = 0; i < k; i++) {
    long long int ll, rr;
    cin >> ll;
    cin >> rr;
    l[i] = ll;
    r[i] = rr;
    for (auto p = ll; p <= rr; p++) {
      S.insert(p);
    }
  }
  auto cnt = f(S, n - 1, 0);
  cout << cnt << endl;
  return 0;
}
