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