#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
    s.at(i)--;
  }
  vector<int> x(N);
  for (int i = 0; i < N; i++) {
    x.at(i) = 100;
  }
  bool check = true;
  for (int i = 0; i < M; i++) {
    if (x.at(s.at(i)) == 100) {
      x.at(s.at(i)) = c.at(i);
    } else if (x.at(s.at(i)) != c.at(i)) {
      check = false;
      break;
    }
  }
  for (int i = 0; i < N; i++) {
    if (x.at(i) == 100) {
      if (i == 0) {
        x.at(i) = 1;
      } else {
        x.at(i) = 0;
      }
    }
  }
  if (check && x.at(0) != 0) {
    if (N == 1) {
      cout << x.at(0) << endl;
    } else if (N == 2) {
      cout << x.at(0) * 10 + x.at(1) << endl;
    } else {
      cout << x.at(0) * 100 + x.at(1) * 10 + x.at(2) << endl;
    }
  } else {
    cout << -1 << endl;
  }
  return 0;
}
