#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,s,c;
  cin >> N >> M;
  int A[N] = {0};
  bool flag = true;
  
  for(int i = 0; i < M; i++){
    cin >> s >> c;
    if(A[s-1] != 0 && A[s-1] != c){
      flag = false;
      break;
    }else A[s-1] = c;
  }
  int sum = 0;
  if(flag) for(int i = 0; i < N; i++) sum += (A[i] * pow(10, N-i-1));
  else sum = -1;
  if(sum < pow(10, N-1)) sum = -1;
  cout << sum << endl;

}