#include <bits/stdc++.h>
using namespace std;
long long f[200005], l[25], p[25];
signed main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= k; i++) {
    cin >> l[i * 2 - 1] >> l[i * 2];
  }
  sort(l + 1, l + k * 2 + 1);
  p[1] = l[1];
  long long m = 1;
  for (long long i = 2; i <= k * 2; i++) {
    while (l[i] == l[i - 1] && i < k * 2) {
      i++;
    }
    m++;
    p[m] = l[i];
  }
  f[1] = 1;
  for (long long i = 2; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (p[j] <= i) {
        f[i] += f[i - p[j]];
        f[i] %= 998244353;
      }
    }
  }
  cout << f[n];
  return 0;
}
