#include <bits/stdc++.h>
using namespace std;
long long cal(long long N, vector<int> vec1) {
  long long c = vec1.size(), count = 0;
  for (long long l = 0; l < c; l++) {
    if (vec1.at(l) > N) {
      continue;
    }
    if (N == vec1.at(l)) {
      count++;
      continue;
    }
    if (N > vec1.at(l)) {
      count = cal(N - vec1.at(l), vec1) + count;
    }
  }
  return count;
}
int main() {
  long long N, K;
  cin >> N >> K;
  long long a, b;
  vector<int> vec1 = {};
  for (long long i = 0; i < K; i++) {
    cin >> a >> b;
    for (long long i = 0; i <= b - a; i++) {
      vec1.push_back(a + i);
    }
  }
  long long d = cal(N - 1, vec1);
  cout << d << endl;
}
