#include <bits/stdc++.h>
using namespace std;
using graph = vector<vector<int>>;
const int MOD = 998244353;
int main() {
  int A, k;
  cin >> A >> k;
  vector<pair<int, int>> vec(0);
  for (int i = (int)(0); i < (int)(k); i++) {
    int x, y;
    cin >> x >> y;
    pair<int, int> p = make_pair(x, y);
    vec.push_back(p);
  }
  vector<int> a(0);
  int dp[A + 10][A + 10];
  int hoge = 0;
  for (int i = (int)(0); i < (int)(vec.size()); i++) {
    while (vec.at(i).first != vec.at(i).second + 1) {
      a.push_back(vec.at(i).first);
      vec.at(i).first++;
    }
  }
  int n = a.size();
  memset(dp, 0, sizeof(dp));
  dp[0][1] = 1;
  for (int i = (int)(0); i < (int)(n); i++) {
    for (int j = (int)(1); j < (int)(A + 1); j++) {
      (dp[i + 1][j] += dp[i][j]) %= MOD;
      if (j >= a.at(i)) {
        (dp[i + 1][j] += dp[i][j - a.at(i)]) %= MOD;
      }
    }
  }
  cout << dp[n][A];
}
