#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    A[i] = 0;
  }
  for(int i=0;i<M;i++){
    int a, b;
    cin >> a >> b;
    if(a == 1&&b==0 && N!= 1){
      cout << -1 << endl;
      return 0;
    }
    if(A[a-1] != 0 && A[a-1] != b){
      cout << -1 << endl;
      return 0;
    }else{
      A[a-1] = b;
    }
  }
  if(A[0] == 0 && N!=1)A[0] = 1;
  for(int i=0;i<N;i++){
    cout << A[i];
  }
  cout << endl;
}
  
