#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long N, ans = 0, K;
  cin >> N >> K;
  vector<long long> L(K), R(K);
  map<long long, long long> mp;
  vector<long long> S(0);
  for (long long i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
    if (L[i] == R[i])
      S.push_back(L[i]);
    else {
      S.push_back(L[i]);
      S.push_back(R[i]);
    }
  }
  sort(S.begin(), S.end());
  mp[1] = 1;
  for (long long i = 1; i < N; i++) {
    for (long long j = 0; j < S.size(); j++) {
      long long X = i + S[j];
      if (X > N)
        break;
      else if (X < N)
        mp[X] += mp[i];
      else if (X == N) {
        ans += mp[i];
      }
    }
  }
  cout << ans % 998244353 << endl;
}
