#include <bits/stdc++.h>
using namespace std;
int n, k, l[210], r[210];
int dp[210], pfxsum[210];
inline void DP() {
  dp[1] = 1;
  for (int cur = 1, begin, end; cur <= n; cur++) {
    for (int idx = 1; idx <= k; idx++) {
      begin = max(1, cur - r[idx]);
      end = max(0, cur - l[idx]);
      if (begin <= end) {
        dp[cur] =
            dp[cur] + (pfxsum[end] + 998244353 - pfxsum[begin - 1]) % 998244353;
        dp[cur] %= 998244353;
      }
    }
    pfxsum[cur] = (pfxsum[cur - 1] + dp[cur]) % 998244353;
  }
}
inline void Monitor() {
  for (int i = 1; i <= n; i++) {
    printf("%d ", dp[i]);
  }
  puts("");
}
inline void Process() { DP(); }
inline void ReadIn() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d %d", l + i, r + i);
  }
}
inline void PrintAns() { printf("%d\n", dp[n]); }
int main() {
  ReadIn();
  Process();
  PrintAns();
  return 0;
}
