#include <bits/stdc++.h>
using namespace std;
const int M = 998244353;
unsigned long long int ar[15];
int32_t main(void) {
  unsigned long long int t = 1;
  while (t--) {
    unsigned long long int n, z;
    cin >> n >> z;
    unsigned long long int k = z;
    set<unsigned long long int> s;
    while (k--) {
      unsigned long long int x, y;
      cin >> x >> y;
      s.insert(x);
      s.insert(y);
    }
    unsigned long long int ans = 0;
    for (auto i : s) {
      ar[ans] = i;
      ans++;
    }
    unsigned long long int N = n - 1;
    unsigned long long int m = ans;
    unsigned long long int count[N + 1];
    memset(count, 0, sizeof(count));
    count[0] = 1;
    for (unsigned long long int i = 1; i <= N; i++) {
      for (unsigned long long int j = 0; j < m; j++) {
        if (i >= ar[j]) {
          count[i] = ((count[i] % M) + (count[i - ar[j]])) % M;
          count[i] %= M;
        }
      }
    }
    cout << (count[N] + M) % M << "\n";
  }
  return 0;
}
