#include <bits/stdc++.h>
using namespace std;
int n, ans, k;
set<int> s;
int dp[222222];
signed main() {
  cin >> n >> k;
  for (int i = 0; i < (int)(k); i++) {
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++) s.insert(i);
  }
  dp[0] = 1;
  for (int i = 0; i < (int)(n); i++) {
    for (auto x : s) {
      dp[i + x] += dp[i];
      dp[i + x] %= 998244353;
    }
  }
  cout << dp[n - 1] << endl;
}
