#include <bits/stdc++.h>
using namespace std;
constexpr int64_t mod{998244353};
int main() {
  int64_t n, k, l, r;
  cin >> n >> k;
  vector<int64_t> s;
  for (int64_t i = 0; i < k; i++) {
    cin >> l >> r;
    if (l == r) {
      s.push_back(l);
    } else {
      s.push_back(l);
      s.push_back(r);
    }
  }
  sort(s.begin(), s.end());
  vector<int64_t> z(n, 0);
  z[0] = 1;
  for (int64_t i = 1; i < n; i++) {
    for (auto& j : s) {
      if (0 <= i - j) {
        z[i] += (z[i - j]) % mod;
        z[i] %= mod;
      } else {
        break;
      }
    }
  }
  cout << z[n - 1] << endl;
}
