#include <bits/stdc++.h>
void quick_sort(int *array, int left, int right) {
  int i, j, n;
  int left_key = left, right_key = right;
  int pivot = array[(left + right) / 2];
  while (1) {
    while (array[left_key] < pivot) {
      left_key++;
    }
    while (array[right_key] > pivot) {
      right_key--;
    }
    if (left_key >= right_key) {
      break;
    }
    n = array[left_key];
    array[left_key] = array[right_key];
    array[right_key] = n;
    left_key++;
    right_key--;
  }
  if ((left_key - left) > 1) {
    quick_sort(array, left, left_key - 1);
  }
  if ((right - right_key) > 1) {
    quick_sort(array, right_key + 1, right);
  }
}
int main() {
  int scnt = 0, x, y, i, j, k, N, K;
  scanf("%d %d", &N, &K);
  int S[N], dp[N];
  for (i = 0; i < K; i++) {
    scanf("%d %d", &x, &y);
    for (j = x; j <= y; j++) {
      S[scnt] = j;
      scnt++;
    }
  }
  quick_sort(S, 0, scnt - 1);
  for (i = 0; i < N; i++) {
    dp[i] = 0;
  }
  for (i = 0; i < scnt; i++) {
    dp[S[i]]++;
  }
  for (i = 0; i < N; i++) {
    for (j = 0; j < scnt; j++) {
      dp[i + S[j]] = dp[i + S[j]] + dp[i];
    }
  }
  printf("%d", dp[N - 1]);
  return 0;
}
