#include <bits/stdc++.h>
using namespace std;
template <typename... T>
void rd(T&... args) {
  ((cin >> args), ...);
}
template <typename... T>
void pp(T... args) {
  ((cout << args << " "), ...);
  cout << "\n";
}
void solve() {
  long long int n, k;
  rd(n, k);
  vector<long long int> arr(n + 2, 0);
  arr[1] = 1;
  vector<pair<long long int, long long int> > a;
  for (long long int i = 0; i < k; i++) {
    long long int l, r;
    rd(l, r);
    a.push_back({l, r});
  }
  long long int sum = 0;
  for (__typeof(n + 1) i = (1) - ((1) > (n + 1));
       i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) {
    for (auto v : a) {
      long long int l = v.first;
      long long int r = v.second;
      if (i + l > n) continue;
      l = min(n, l + i);
      r = min(n, r + i);
      for (long long int j = l; j <= r; j++) arr[j] += arr[i];
    }
  }
  pp(arr[n]);
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  solve();
  return 0;
}
