#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define all(a)  (a).begin(),(a).end()

int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
signed main(){
  int n,m;
  cin>>n>>m;
  V<P<int,int>> a(m);
  fo(i,m){
    cin>>a[i].fi>>a[i].se;
  }
  Sort(a);
  fo(i,m-1){
    if(a[i].fi==a[i+1].fi){
      if(a[i].se!=a[i+1].se){
        cout<<-1<<endl;
        return 0;

      }
    }
  }
  if(n==1){
    fo(i,m){
      int x=1;
      if(a[i].se==0)
        x=x;
      else
        x++;
    }
    if(x){
      cout<<0<<endl;
      return 0;
    }
  }
  for(int i=1; i<=999; i++){
    if(keta(i)!=n)
      continue;
    string f=to_string(i);
    int c=1;
    fo(k,m){
      if(f[a[k].fi-1]-'0'!=a[k].se){
        c=0;
      }
 
    }
    if(c){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}