#include <bits/stdc++.h>
using namespace std;

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> vec(n,0);
  vector<int> count(n,0);
  bool flag = true;
  
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    if (count[a-1] == 0){
      vec[a-1] = b;
      count[a-1] = 1;
    } 
    else{
      if (vec[a-1] != b) flag = false;
    }
  }
  
  if (n==1 && m==0) cout << 0 << endl;
  else if(n==1 && m>0){
    if (flag == true) cout << vec[0] << endl;
    else cout << -1 << endl;
  else if (n==2 && m==0) cout << 10 << endl;
  else if (n==3 && m==0) cout << 100 << endl;
  else if (n>1){
    if(flag=true&&vec[0]!=0){
      for(int i:vec){
        cout << i;
      }
      cout << endl;
    }
  else cout << -1 << endl;
  }
 }
}