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

int main() { 
  int N, M;
  int s, c;
  cin >> N >> M;
  
  vector<int> n(N, 10);
  
  for(int i = 0; i < M; i++) {
    cin >> s >> c;
    if(n[s-1] == 10 || n[s-1] == c) {
      n[s-1] = c;
    }
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  
  if(n[0] != 10 && n[0] != 0) {
    for(int i  = 0; i < N; i++) {
      if(n[i] == 10)
        cout << 0;
      else
      	cout << n[i];
    }
    cout << endl;
  }
  else if(N == 1)
    cout << n[i];
  else {
    cout << -1 << endl;
  }
  return 0; 
}