#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int main() {
  int N, K;
  cin >> N >> K;
  vector<pii> rng;
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    r++;
    rng.emplace_back(l, r);
  }
  vector<ll> dp(N);
  dp[0] = 1;
  dp[1] = -1;
  for (int i = 0; i < N; i++) {
    if (i > 0) dp[i] += dp[i - 1];
    for (int j = 0; j < K; j++) {
      int l, r;
      tie(l, r) = rng[j];
      if (i + l < N) dp[i + l] += dp[i];
      if (i + r < N) dp[i + r] -= dp[i];
    }
  }
  cout << dp[N - 1] << endl;
  return 0;
}
