#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main()	{
  int n,m;
  cin>>n>>m;
  vector<int>s(m),c(m);
  rep(i,m) cin>>s[i]>>c[i];
  rep(x,1000){
    int nx=x/10;
    vector<int>d(3);
    d[0]=x%10;
    while(nx){
      int i=1;
      d[i]=nx%10;
      nx/=10;
      i++;
    }
    reverse(all(d));
    int c=0;
    rep(j,m){
      if(d[s[j]]==c[j])
        c++;
    }
    if(c=3){
      cout<<x<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}
