#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ii = pair<int, int>;
using ll = long long;
int mod = 998244353;
int dp[200004];
int b[11];
int e[11];
int main() {
  memset(dp, 0, sizeof dp);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> b[i] >> e[i];
  }
  dp[0] = 1;
  int temp[10] = {0};
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int m = e[j];
      int l = b[j];
      int s = i - m - 1;
      int e = i - l;
      if (s >= 0) {
        temp[j] -= dp[s];
      }
      if (e >= 0) temp[j] += dp[e];
      dp[i] += temp[j];
    }
  }
  cout << dp[n - 1];
  return 0;
}
