#include <iostream>
#include <sstream>
using namespace std;

int main(void) {
  string str;
  int n, m;
  int b, c;
  int a[3] = {};
  
  getline(cin, str);
  istringstream s(str);
  s >> n >> m;
  
  for(int i=0; i<m; i++){
    getline(cin, str);
    istringstream s(str);
    s >> b >> c;
    if(a[b-1] >= c || a[b-1]==0) {
      if(3-n == b-1 && c == 0) continue;
      a[b-1] = c;
    }
  }
  
  if(a[3-n]!=0){
    for(int i=0; i<n; i++){
      cout << a[i];
    }
    cout << endl;
  }
  else{
      cout << -1 << endl;
  }
  
  
  return 0;