#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
ll cnt = 0;
ll size;
ll n, k;
string d;
void solve(ll sum) {
  if (sum == n) {
    cnt++;
    cnt %= 998244353;
    return;
  } else if (sum > n) {
    return;
  }
  for (ll i = 0; i < size; i++) {
    solve(sum + d[i]);
  }
}
int main() {
  cin >> n >> k;
  ll r, l;
  for (ll i = 0; i < k; i++) {
    cin >> l >> r;
    for (ll j = l; j <= r; j++) {
      d += j;
    }
  }
  size = d.size();
  solve(1);
  cout << cnt << endl;
}
