#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
bool prime[100005];
void Sieve(int n) {
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
}
vector<int> grapj[100005];
bool vis[100005];
int numSubseq(vector<int>& nums, int target) {
  sort(nums.begin(), nums.end());
  int len = nums.size();
  int arrdp[len];
  int frontptr = 0;
  int backptr = nums.size() - 1;
  int totalsum = 0;
  for (int i = 0; i < len; i++) arrdp[i] = 1;
  int MOD = 998244353;
  for (int i = 1; i < len; i++) {
    arrdp[i] = arrdp[i - 1] * 2;
    if (arrdp[i] >= MOD) arrdp[i] -= MOD;
  }
  while (frontptr <= backptr) {
    if (nums[frontptr] + nums[backptr] <= target) {
      totalsum += arrdp[backptr - frontptr];
      frontptr++;
      if (totalsum >= MOD) totalsum -= MOD;
    } else
      backptr--;
  }
  return totalsum;
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> d;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++) d.push_back(j);
  }
  sort(d.begin(), d.end());
  cout << numSubseq(d, n);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
}
