#include <bits/stdc++.h>
using namespace std;
using lld = long long int;
using ld = long int;
int main() {
  lld i, j, n, k;
  cin >> n >> k;
  vector<lld> vec(n + 1, 0);
  vec[0] = 0;
  vec[1] = 1;
  vector<lld> steps;
  while (k--) {
    lld i, l, k;
    cin >> l >> k;
    for (i = l; i <= k; i++) {
      steps.push_back(i);
    }
  }
  for (i = 2; i < n + 1; i++) {
    j = i - 1;
    for (j = i - 1; j > 0; j--) {
      if (binary_search(steps.begin(), steps.end(), i - j)) {
        vec[i] += vec[j];
      }
    }
  }
  cout << vec[n];
}
