#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, k;
  cin >> n >> k;
  set<int> s;
  while (k--) {
    int l, r;
    cin >> l >> r;
    l %= 998244353;
    r %= 998244353;
    s.insert(l);
    s.insert(r);
  }
  int coins[s.size()], l = 0;
  set<int>::iterator itr;
  for (itr = s.begin(); itr != s.end(); itr++) {
    coins[l] = *itr;
    l++;
  }
  int dp[n + 1];
  memset(dp, 0, sizeof(dp));
  dp[0] = 0;
  dp[1] = 1;
  for (long long int i = 2; i < n + 1; i++) {
    for (long long int j = 0; j < l; j++) {
      if (i - coins[j] >= 0) {
        dp[i] += dp[i - coins[j]];
        dp[i] %= 998244353;
      }
    }
  }
  cout << dp[n] << "\n";
  return 0;
}
