#include <bits/stdc++.h>
using namespace std;
long long f[200005], l[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];
  }
  f[0] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= k * 2; j++) {
      if (l[j] >= i) {
        f[i] += f[i - l[j]];
        f[i] %= 998244353;
      }
    }
  }
  cout << f[n];
  return 0;
}
