#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
lint dp[400000];
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> d(k);
  for (int i = 0; i < k; i++) cin >> d[i].first >> d[i].second;
  vector<lint> e(300000, 0);
  for (int i = 0; i < 300000; i++) {
    for (int j = 0; j < k; j++) {
      if (i + d[j].first >= 300000) goto kaage;
      e[i + d[j].first] += 1 + e[i];
    kaage:;
      if (i + d[j].second >= 300000) goto Cyan;
      e[i + d[j].second] -= 1 + e[i];
    Cyan:;
    }
  }
  vector<lint> ans(250000);
  for (int i = 0; i < 250000; i++) {
    ans[i] += e[i];
  }
  cout << ans[n] << endl;
  return 0;
}
