#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using vvb = vector<vb>;
int main() {
  int n, k;
  cin >> n >> k;
  vi s;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j < r + 1; j++) {
      if (!count(s.begin(), s.end(), j)) {
        s.push_back(j);
      }
    }
  }
  ll cnt = 0;
  for (int i = 0; i < (1 << k); i++) {
    ll ps = 0;
    for (int j = 0; j < k; j++) {
      if (ps != 0) ps -= s[j - 1];
      while (ps <= n) {
        if (i & (1 << j)) {
          ps += s[j];
        }
      }
      if (ps == n) {
        cnt = (cnt + 1) % 998244353;
      }
    }
  }
  cout << cnt << endl;
}
