#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int answer = 0;
  vector<int> v_1(N);
  vector<int> v_s(M);
  vector<int> v_c(M);
  for (int l = 0; l < M; ++l) {
    cin >> v_s.at(l);
    cin >> v_c.at(l);
  }
  for (int k = 0; k < M; ++k) {
    v_1.at((v_s.at(k) - 1)) = v_c.at(k);
  }
  if (N == 1) {
    answer = v_1.at(0);
  } else if (N == 2) {
    answer = v_1.at(0) * 10 + v_1.at(1);
  } else {
    answer = v_1.at(0) * 100 + v_1.at(1) * 10 + v_1.at(2);
  }
  if (N > 1 && v_1.at(0) == 0) {
    answer = -1;
  }
  for (int i = 0; i < M; ++i) {
    for (int j = 0; j < M; ++j) {
      if (i == j) {
      } else if (v_s.at(i) == v_s.at(j) && v_c.at(i) != v_c.at(j)) {
        answer = -1;
      }
    }
  }
  cout << answer << endl;
}
