#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long MX = 1e9;
const long long INF = 1e9;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  int l[k], r[k];
  for (int i = 0; i < k; ++i) cin >> l[i] >> r[i];
  int ans[n + 1], sum[n + 1];
  sum[0] = 0;
  ans[1] = 1;
  sum[1] = 1;
  for (int i = 2; i < n + 1; ++i) {
    ans[i] = 0;
    for (int j = 0; j < k; ++j) {
      if (i - r[j] >= 1) {
        ans[i] += (sum[i - l[j]] - sum[i - r[j] - 1]);
      } else if (i - l[j] >= 1) {
        ans[i] += sum[i - l[j]];
      }
    }
    sum[i] = sum[i - 1] + ans[i];
  }
  cout << ans[n] << '\n';
  return 0;
}
