#include <bits/stdc++.h>
using namespace std;
long long n, ans, k;
long long l[15], r[15], x[25], s[400005], sum[400005];
const long long mod = 998244353;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  int flag = 0;
  int cnt = 1;
  for (int i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
  }
  sum[0] = 1;
  for (int i = 1; i <= n; i++) {
    sum[i] = (sum[i - 1] + s[i] + 10 * mod) % mod;
    for (int j = 1; j <= k; j++) {
      s[i + l[j]] += sum[i];
      s[i + r[j] + 1] -= sum[i];
    }
  }
  cout << sum[n] - sum[n - 1];
}
