#include <bits/stdc++.h>
using namespace std;
int n, k;
struct node {
  int L, R;
} Data[200010];
int dp[200010];
bool cmp(node A, node B) { return A.L < B.L; }
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) scanf("%d%d", &Data[i].L, &Data[i].R);
  sort(Data + 1, Data + k + 1, cmp);
  dp[1] = 1;
  for (register int i = 2; i <= n; i++) {
    for (register int j = 1; j <= k; j++) {
      bool ok = 1;
      for (register int tmp = Data[j].L; tmp <= Data[j].R; tmp++) {
        if (tmp < i)
          dp[i] = (dp[i] + dp[i - tmp]) % 998244353;
        else {
          ok = 0;
          break;
        }
      }
      if (!ok) break;
    }
  }
  cout << dp[n];
  return 0;
}
