#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int r = 0, f = 1;
  register char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    r = (r << 1) + (r << 3) + c - '0';
    c = getchar();
  }
  return r * f;
}
const int N = 200000 + 2, INF = 0x3f3f3f3f, Mod = 998244353;
int n, k;
int a[N], b[N];
vector<int> v;
queue<int> q;
long long f[N];
long long s;
long long dfs(int p) {
  if (p > n) return 0;
  if (n == p) s++;
  for (int i = 0; i <= v.size() - 1; ++i) {
    dfs(p + v[i]);
  }
  return s;
}
int main() {
  n = read();
  k = read();
  for (int i = 1; i <= k; ++i) {
    a[i] = read();
    b[i] = read();
    for (int j = a[i]; j <= b[i]; ++j) v.push_back(j);
  }
  cout << dfs(1) << '\n';
  system("pause");
  return 0;
}
