#include <bits/stdc++.h>
using namespace std;

long long COM = 998244353;

int main() {

  int N, K;
  scanf("%d %d", &N, &K);

  vector<int> L(K);
  vector<int> R(K);

  for (int i=0;i<K;i++){
    scanf("%d %d", &L[i], &R[i]);
  }

  vector<int> v(2*N+1);
  v[1] = 1;
  v[2] = -1;

  for (int i=1;i<N;i++){
    for (int j=0;j<K;j++){
      v[i+L[j]]+=v[i];
      v[i+L[j]]%=COM;
      v[i+R[j]+1]-=v[i];
      v[i+L[j]+1]+=COM;
      v[i+L[j]+1]%=COM;
    }

    v[i+1]+=v[i];
    v[i+1]%=COM;
  }

  printf("%d\n", v[N]);

  
  return 0;
}


