#include <bits/stdc++.h>
#include<vector>
using namespace std;
 
int main() {
  int a,b,e,f;
  cin>>a>>b;
  vector<int>c(a,0);
  bool d[a];
  rep(i,a)d[i]=false;
  rep(i,b){
    cin>>e>>f;
    if(d[e]==true&&d[e]!=c[e]){
	  cout<<-1;
      return 0;
    }
    c[e]=f;
    d[e]=true;
  }
  rep(i,a){
    if(i==0&&c[i]==0){
      cout<<1;
    }
    else cout<<c[i];
  }
}