#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, j, a, count;
  cin >> N;
  cin >> M;
  vector<int> vec(N, 0);
  vector<int> zero(N, false);
  count = 0;
  for (int i = 0; i < M; i++) {
    cin >> j;
    cin >> a;
    if (zero.at(j - 1) == true && !(vec.at(j - 1) == a)) {
      cout << -1 << endl;
      break;
    } else if (zero.at(j - 1) == true && vec.at(j - 1) == a) {
      vec.at(j - 1) = a;
      zero.at(j - 1) = true;
      count++;
    } else {
      vec.at(j - 1) = a;
      zero.at(j - 1) = true;
      count++;
    }
  }
  if (count < M) {
  } else {
    if (vec.size() == 1 && vec.at(0) == 0) {
      cout << 0 << endl;
    } else if (M = 0) {
      if (N = 1)
        cout << 0 << endl;
      else if (N = 2)
        cout << 10 << endl;
      else if (N = 3)
        cout << 100 << endl;
    } else if (vec.at(0) == 0) {
      cout << -1 << endl;
    } else {
      for (int i = 0; i < N; i++) {
        cout << vec.at(i);
      }
      cout << endl;
    }
  }
}
