<?php

fscanf(STDIN, "%d%d", $n, $k);

const MOD = 998244353;

$set = [];
for ($i = 0; $i < $k; ++$i) {
    fscanf(STDIN, "%d%d", $l, $r);
    $set = array_merge($set, range($l, $r));
}

$path = [1 => 1];
for ($i = 2; $i <= $n; ++$i) {
    $path[$i] = 0;
    foreach ($set as $number) {
        if (isset($path[$i - $number])) {
            $path[$i] = ($path[$i] + $path[$i - $number]) % MOD;
        }
    }
}

echo $path[$n];
