#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long smod = 998244353;
struct aaa {
  aaa() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} aaaaaaa;
const double pi = acos(-1.0);
const long long inf = 1LL << 60;
bool isPrime(long long n) {
  if (n < 2) return false;
  for (long long x = 2; x * x <= n; x++) {
    if (n % x == 0) return false;
  }
  return true;
}
long long kaizyo(long long k) {
  long long sum = 1;
  for (int i = 1; i <= k; i++) {
    sum *= i;
    sum %= mod;
  }
  return sum;
}
long long ncr(long long n, long long r) {
  return kaizyo(n) / (kaizyo(r) * kaizyo(n - r));
}
unsigned keta(unsigned num) { return log10(num) + 1; }
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
int main() {
  long long n, k;
  cin >> n >> k;
  ;
  vector<long long> l(k), r(k);
  for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
  vector<long long> s(n + 1, 0), cnt(n + 1, 0);
  cnt[1] = 1;
  for (int i = 1; i <= n + 1; i++) {
    for (int j = 0; j < k; j++) {
      if (l[j] <= i && i <= r[j]) s[i]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i - 1; j++) {
      if (s[i - j] > 0) {
        cnt[i] += cnt[i - j];
      }
    }
  }
  cout << cnt[3] << "\n";
}
