#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
unordered_map<long long, vector<long long>> adj;
vector<long long> vis(300005, 0);
vector<long long> p(100005, 0);
long long c[100005];
long long cnt;
long long n;
void dfs(long long node) {
  if (vis[node]) return;
  vis[node] = 1;
  cnt++;
  for (auto i : adj[node]) {
    dfs(i);
  }
}
struct range {
  long long l;
  long long r;
  long long index;
};
bool cmp(range& p1, range& p2) { return p1.l < p2.l; }
int main() {
  long long n, k;
  cin >> n >> k;
  long long a, b;
  vector<long long> v;
  long long dp[n + 1];
  while (k--) {
    cin >> a >> b;
    if (a == b)
      v.push_back(a);
    else {
      v.push_back(a);
      v.push_back(b);
    }
  }
  memset(dp, 0, sizeof(dp));
  dp[1] = 1;
  long long j, i;
  for (i = 2; i <= n; i++) {
    for (j = 0; j < v.size(); j++) {
      if (i - v[j] >= 0) {
        dp[i] += dp[i - v[j]];
      }
    }
  }
  cout << dp[n];
}
