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

int main() {
  ostringstream oss;
  int n, m, flag=0, sum=0;
  cin >> n >> m;
  vector<int> vec(n); //-1で初期化
  for (int i = 0; i < n; i++) {vec.at(i) = -1;}
  
  for (int i = 0; i < m; i++) {
    int s,c;
    cin >> s >> c;
    if (vec.at(s-1) == -1 || vec.at(s-1) == c) {
      vec.at(s-1) = c;
    }else{
      flag = -1;
      cout << -1;
      break;
    }
  }
  for (int i = 0; i < n; i++){
    if (vec.at(i) > 0){
      sum += vec.at(i) * pow(10 , n-i-1);
    }
  }
  if (n > 1 && vec.at(1) <= 0){
    flag = -1;
    count << -1;
  }else if (flag == 0){
    cout << sum;
  }
}