#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int m;
  cin >> N;
  cin >> m;
  int S;
  int M;
  int i;
  int out = 0;
  vector<int> vec(3);
  for (i = 0; i < 3; i++) {
    vec.at(i) = -1;
  }
  for (i = 0; i < m; i++) {
    cin >> S;
    cin >> M;
    if (vec.at(S - 1) != -1 && vec.at(S - 1) != M) {
      out = -1;
      i = m;
    } else {
      vec.at(S - 1) = M;
    }
  }
  if (out == -1) {
    cout << -1 << endl;
  } else if (N == 3) {
    if (vec.at(0) == 0) {
      out = -1;
    } else if (vec.at(0) == -1) {
      cout << 100 + vec.at(1) * 10 + vec.at(2) << endl;
    } else if (vec.at(1) == -1) {
      cout << vec.at(0) * 100 + vec.at(2) << endl;
    } else if (vec.at(0) && vec.at(1) == -1) {
      cout << 100 + vec.at(2) << endl;
    } else {
      cout << vec.at(0) * 100 + vec.at(1) * 10 + vec.at(2) << endl;
    }
  } else if (N == 2) {
    if (vec.at(0) == 0) {
      out = -1;
    } else if (vec.at(0) == -1) {
      cout << 10 + vec.at(1) << endl;
    } else {
      cout << vec.at(0) * 10 + vec.at(1) << endl;
    }
  } else {
    cout << -1 << endl;
  }
}
