void main() {
  problem();
}

void problem() {
  const N = scan!ulong - 1;
  const K = scan!int;
  const steps = K.iota.map!(x => iota(scan!ulong, 1 + scan!ulong)).array.joiner.array;
  steps.deb;

  ulong solve() {
    ulong ans;
    
    auto dp = new ulong[N + 1];
    dp[0] = 1;

    auto posHeapSource = new ulong[1];
    posHeapSource[0] = 0;
    auto posHeap = posHeapSource.heapify!"a > b";

    while(posHeap.length > 0) {
      const pos = posHeap.front;
      while(posHeap.length > 0 && posHeap.front == pos) posHeap.removeFront();
      // [[pos]].deb;

      foreach(s; steps) {
        const n = pos + s;
        if (n > N) continue;

        [n, pos, dp[pos]].deb;
        dp[n] += dp[pos];
        dp[n] %= MOD;
        if (n < N) {
          posHeap.insert(n);
        }
      }
      // dp.deb;
    }

    dp.deb;
    return dp[$-1];
  }

  solve().writeln;
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
const MOD = 998244353;

// -----------------------------------------------
