#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define map map<string,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())

using namespace std;
int main() {
  ll N,M;
  cin>>N>>M;
  vec A(M),B(M);
  rep(i,0,M) {
    cin>>A[i]>>B[i];
  }
  bool ans=true;
  rep(i,0,M-1) {
    rep(j,i+1,M) {
      if(A[i]==A[j]) {
        if(B[i]!=B[j]) {
          
          ans=false;
        }
        else
          A[i]=0;
          B[i]=0;
      }
    }
      
  }
  if(N>1) {
    rep(i,0,M) {
      if(A[i]==1 && B[i]==0)
        ans=false;
    }
  }
      
    
  if(ans) {
    if(N>1 && M>0) {
      ll K=0;
      rep(i,0,M) {
        K+=B[i]*pow(10,N-A[i]);
      }
      if(K<pow(10,N-1)) {
        cout<<K+pow(10,N-1)<<endl;
      }
      else
        cout<<K<<endl;
    }
    if(N>1 && M==0) {
      cout<<pow(10,N-1)<<endl;
    }
    if(N==1 && M==0)
      cout<<0<<endl;
    if(N==1 M==1) {
      if(A[i]==1 && B[i]==0)
        cout<<"0"<<endl;
    }
  }
 
  else
    cout<<"-1"<<endl;
}
    
  