#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
map<int, int> p;
int a[200000];
int dp[2000000];
int main() {
  int m, n, i, j, t, k, s = 1;
  cin >> n >> k;
  int l, r;
  for (i = 1; i <= k; i++) {
    cin >> l >> r;
    for (j = l; j <= r; j++) {
      a[s++] = j;
    }
  }
  dp[0] = 1;
  for (i = 0; i <= n - 1; i++) {
    for (j = 1; j < s; j++) {
      if (i >= a[j]) dp[i] += dp[i - a[j]];
      dp[i] %= 998244353;
    }
  }
  cout << dp[n - 1];
}
