#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<(int)N;i++)
int main()
{
  int N,M,a=0,x,y;
  cin>>N>>M;
  vector<int> used(3,0);
  rep(i,M)
  {
    cin>>x>>y;
    if(N>1&&x==1&&y==0){cout<<-1<<endl;return 0;}
    if(used.at(x-1)!=0&&used.at(x-1)!=y){cout<<-1<<endl;return 0;}
    if(used.at(x-1)==0)a+=pow(10,N-x)*y;
    used.at(x-1)=y;
  }
  if(N>1&&pow(10,N-1)>a)a+=pow(10,N-1);
  cout<<a<<endl;
}