#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const long long mod = 998244353;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 10;
const int maxm = 100 + 10;
long long dp[maxn];
int vis[maxn];
int n, k;
int main() {
  cin >> n >> k;
  vector<int> e;
  for (int i = 1; i <= k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      if (!vis[j]) e.push_back(j);
      vis[j] = 1;
    }
  }
  sort(e.begin(), e.end());
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < e.size(); j++) {
      if (i - e[j] < 1) break;
      int t = e[j];
      dp[i] = (dp[i] + dp[i - t]) % mod;
    }
  }
  cout << dp[n] << endl;
}
