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