#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  rep(i, m){
    cin >> s[i] >> c[i];
  }
  bool zero=true;
    rep(i, m){
      if(c[i]!=0){
        zero=false;
        break;
      }
    }

  if(zero && n==1){
    cout << "0" << endl;
    return 0;
  }
  repo(i, 999){
    int i2=i;
    bool nflag=true;
    rep(j, n){
      if(i2==0){
        nflag=false;
        break;
      }
      i2/=10;
    }
    if(i2!=0){
      nflag=false;
    }
    if(!nflag){
      continue;
    }
    bool scflag=true;
    rep(j, m){
      int i3=i;
      int sn=n-s[j];
      rep(k, sn){
        i3/=10;
      }
      i3%=10;
      if(i3!=c[j]){
        scflag=false;
        break;
      }
    }
    if(scflag){
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}

/*
 * Author: ylx
 * Lang: c++
 * Prog: agc002F
 */
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void qmax(int &x, int y)
{
    if (x < y)
        x = y;
}
void qmin(int &x, int y)
{
    if (x > y)
        x = y;
}
inline ll read()
{
    char s;
    ll k = 0, base = 1;
    while ((s = getchar()) != '-' && s != EOF && !(isdigit(s)))
        ;
    if (s == EOF)
        exit(0);
    if (s == '-')
        base = -1, s = getchar();
    while (isdigit(s))
        k = k * 10 + (s ^ '0'), s = getchar();
    return k * base;
}
inline void write(ll x)
{
    static char cnt, num[20];
    cnt = 0;
    if (!x)
    {
        putchar('0');
        return;
    }
    for (; x; x /= 10)
        num[++cnt] = x % 10;
    for (; cnt; putchar(num[cnt--] + 48))
        ;
}
const int maxn = 4e6 + 100;
const ll mod = 1e9 + 7;
int jie[maxn], ny[maxn];
int n, m;
ll ksm(ll x, int y)
{
    ll sum = 1;
    while (y)
    {
        if (y & 1)
            sum = sum * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return sum;
}
void init()
{
    n = 4e6;
    jie[0] = 1;
    for (int i = 1; i <= n; i++)
        jie[i] = (ll)jie[i - 1] * i % mod;
    ny[n] = ksm(jie[n], mod - 2);
    for (int i = n; i >= 1; i--)
        ny[i - 1] = (ll)ny[i] * i % mod;
}
ll C(int x, int y)
{
    if (x < y)
        return 0;
    return (ll)jie[x] * ny[x - y] % mod * ny[y] % mod;
}
ll f[2][2030];
int main()
{
#ifdef ylx
    freopen("agc002F.in", "r", stdin);
    freopen("agc002F.out", "w", stdout);
#endif
    init();
    n = read(), m = read();
    if (m == 1)
    {
        cout << 1 << endl;
        return 0;
    }
    f[0][0] = 1;
    for (int i = 1, p; i <= n; i++)
    {
        p = i & 1;
        memset(f[p], 0, sizeof(f[p]));
        for (int j = 0; j <= i; j++)
        {
            if (!j)
            {
                f[p][j] = f[p ^ 1][j];
                continue;
            }
            f[p][j] = f[p ^ 1][j] + f[p][j - 1] * (n - j + 1) % mod * C((n - j + 1) * (m - 1) + n - i - 1, m - 2) % mod;
        }
    }
    write(f[n & 1][n]);
}