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

int main(){
  int N,M;
  int i;
  int t,u;
  
  cin >> N >> M;
  vector<int> num(N);

  for(i=0;i<M;++i){
    cin >> t >> u;
    if(t == 1 && u == 0 && N != 1){
      cout << -1 << endl;
      return 0;
    }
    if(num.at(t-1) == 0 || num.at(t-1) == u){
      num.at(t-1) = u;
    }else{
      cout << -1 << endl;
      return 0;
    }
  }

  if(num.at(0) == 0 && N != 1){
    num.at(0) = 1;
  }
  for(i=0;i<N;++i){
    cout << num.at(i);
  }
  cout << endl;
}