#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M; cin>>N>>M;
  vector<int>s(M);
  vector<int>c(M);
  vector<vector<bool>>A(N,vector<bool>(10,false));
  for(int i=0;i<M;i++){
    cin>>s[i]>c[i];
    A[s[i]-1][c[i]]=true;
  }
  for(int i=0;i<N;i++){
    if(i==0){
      if(A[0][0]==true){cout<<-1<<endl;return 0;}
      int B=0;
      for(int j=1;j<10;j++)if(A[i][j]==true)B++;
      if(B>1){cout<<-1<<endl;return 0;}
    }
    else{
      int B=0;
      for(int j=0;j<10;j++)if(A[i][j]==true)B++;
      if(B>1){cout<<-1<<endl;return 0;}
    }
  }
  int answer=0;
  for(int i=0;i<N;i++)for(int j=0;j<10;j++){int d=pow(10,N-i);if(A[i][j]==true)answer+=j*d;}
  cout<<(answer<100? answer+100:answer)<<endl;
}