#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const long long MOD = 1000000007;
const long long INF = 1e18;
const long long MAX_N = 201010;
long long fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX_N; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(long long n, long long k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long lcm(long long x, long long y) {
  if (x == 0 || y == 0) return 0;
  return (x / gcd(x, y) * y);
}
long long dx[4] = {0, 0, -1, 1};
long long dy[4] = {-1, 1, 0, 0};
long long dp[201010];
int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> p(k);
  long long waru = 998244353;
  for (long long i = 0; i < k; ++i) {
    long long r, l;
    cin >> l >> r;
    r++;
  }
  dp[0] = 1;
  for (long long i = 0; i < n - 1; ++i) {
    dp[i + 1] += dp[i];
    for (long long j = 0; j < k; ++j) {
      if (i + p[j].first < n) dp[i + p[j].first] += dp[i];
      if (i + p[j].second < n) dp[i + p[j].second] -= dp[i];
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
