#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int mod = 998244353;
int dp[N];
int n, m;
int a[N];
int pos = 0;
int main() {
  scanf("%d%d", &n, &m);
  int le, ri;
  pos = 0;
  while (m--) {
    scanf("%d%d", &le, &ri);
    for (int i = le; i <= ri; i++) {
      a[pos++] = i;
    }
    sort(a, a + pos);
    memset(dp, 0, sizeof(dp));
    dp[1] = 1;
    for (int i = 1; i < n; i++) {
      if (dp[i] == 0) {
        continue;
      }
      for (int j = 0; j < pos && i + a[j] <= n; j++) {
        dp[i + a[j]] = (dp[i + a[j]] + dp[i]) % mod;
      }
    }
    printf("%d\n", dp[n]);
  }
  return 0;
}
