#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<long long int> ways(n + 1, 0), step_size(n + 1, 0);
  while (k--) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) {
      step_size[i] = 1;
    }
  }
  ways[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      if (step_size[j] == 1) {
        ways[i] += (long long int)(ways[i - j]);
      }
    }
  }
  cout << ways[n] << '\n';
  return 0;
}
