#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000 * 1000 * 1000 + 7;
const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
const long long MOD2 = 998244353;
const long long N2 = 70;
const long double PI = 3.141592653589793;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
void solve() {}
long long f(vector<long long> arr, long long m, long long N) {
  long long count[N + 1];
  memset(count, 0, sizeof(count));
  count[0] = 1;
  for (long long i = 1; i <= N; i++)
    for (long long j = 0; j < m; j++)
      if (i >= arr[j]) count[i] += count[i - arr[j]];
  return count[N];
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  set<long long> s;
  while (k--) {
    long long l, r;
    cin >> l >> r;
    for (long long i = l; i <= r; i++) {
      s.insert(i);
    }
  }
  vector<long long> p;
  for (auto i : s) {
    p.push_back(i);
  }
  long long ans = f(p, (long long)p.size(), (n - 1));
  cout << ans;
  return 0;
}
