#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int INF = 2147483647;
const long long MOD = 998244353;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
long long n, m, dp[200005];
vector<int> vec;
map<int, bool> mp;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int(i) = 0; i < (m); i++) {
    int x, y;
    cin >> x >> y;
    for (int j = x; j <= y; j++) {
      if (!mp[j]) {
        mp[j] = 1;
        vec.push_back(j);
      }
    }
  }
  dp[1] = 1;
  sort(vec.begin(), vec.end());
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < vec.size() && i + vec[j] <= n; j++) {
      dp[i + vec[j]] += dp[i];
      dp[i + vec[j]] %= MOD;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
