#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 5e5 + 5, mod = 1e9 + 7;
int incr[maxn], decr[maxn], f[2005][26];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, m; cin >> n >> m;
//điều kiện a, b
//với a < b thì i từ a đến b - 1 phải thỏa s[i] >= s[i + 1]
//với a > b thì i từ b đến a - 1 phải thỏa s[i] <= s[i + 1]
for(int i = 1; i <= m; i++){
int a, b; cin >> a >> b;
if(a < b){
for(int j = a; j < b; j++) incr[j] = max(incr[j], a);
}else{
for(int j = b; j < a; j++) decr[j] = max(decr[j], b);
}
}
for(int c = 0; c < 26; c++) f[1][c] = 1;
for(int i = 2; i <= n; i++){
for(int c = 0; c < 26; c++){
for(int d = 0; d < 26; d++){
if(d == c) continue;
for(int j = ((d < c) ? incr[i - 1] : decr[i - 1]) + 1; j < i; j++) (f[i][c] += f[j][d]) %= mod;
}
}
}
int ans = 0;
for(int k = 1; k <= n; k++){
for(int c = 0; c < 26; c++) (ans += f[k][c]) %= mod;
}
cout << ans;
}