#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
bool prime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
bool isPerfectSquare(long long int x) {
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);
}
bool subsequence_checker(string str1, string str2, long long int m,
                         long long int n) {
  if (m == 0) return true;
  if (n == 0) return false;
  if (str1[m - 1] == str2[n - 1])
    return subsequence_checker(str1, str2, m - 1, n - 1);
  return subsequence_checker(str1, str2, m, n - 1);
}
bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
  if (a.first == b.first) return a.second < b.second;
  return (a.first > b.first);
}
long long int gcd(long long int p, long long int q) {
  if (p % q == 0) return q;
  return gcd(q, p % q);
}
long long int getSumofdigit(long long int n) {
  long long int sum = 0;
  while (n != 0) {
    sum = sum + n % 10;
    n = n / 10;
  }
  return sum;
}
long long int countDigit(long long int n) { return floor(log10(n) + 1); }
long long int printDivisors(long long int n) {
  long long int count = 0;
  for (long long int i = 1; i * i < n; i++) {
    if (n % i == 0) count++;
  }
  for (long long int i = sqrt(n); i >= 1; i--) {
    if (n % i == 0) count++;
  }
  return count;
}
long long int res = 0;
void makep(vector<vector<long long int>>& ans, vector<long long int>& v,
           vector<long long int>& nums, long long int target,
           long long int next) {
  if (target == 0) {
    res++;
    for (long long int i = 0; i < v.size(); i++) {
      cout << v[i] << " ";
    };
    cout << "\n";
    ans.push_back(v);
    return;
  }
  if (next == nums.size() || target - nums[next] < 0) return;
  v.push_back(nums[next]);
  makep(ans, v, nums, target - nums[next], next);
  v.pop_back();
  makep(ans, v, nums, target, next + 1);
}
void combinationSum(vector<long long int>& candidates, long long int target) {
  sort(candidates.begin(), candidates.end());
  vector<long long int> v;
  vector<vector<long long int>> ans;
  makep(ans, v, candidates, target, 0);
  return;
}
long long int combinationSum4(vector<long long int>& nums,
                              long long int target) {
  vector<long long int> result(target + 1);
  result[0] = 1;
  for (long long int i = 1; i <= target; ++i) {
    for (long long int x : nums) {
      if (i >= x)
        result[i] = (result[i] + result[i - x] % 998244353) % 998244353;
    }
  }
  return result[target];
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  map<long long int, long long int> m;
  vector<long long int> a;
  for (long long int i = 0; i < k; i++) {
    long long int l, r;
    cin >> l >> r;
    if (l != r) {
      for (long long int j = l; j <= r; j++) {
        a.push_back(j);
      }
    } else
      a.push_back(l);
  }
  long long int ans = combinationSum4(a, n - 1);
  ans = ans % 998244353;
  cout << ans;
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
