#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  vector<int> ans(N, -1);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    if (ans[s[i] - 1] != -1 && ans[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      exit(0);
    }
    ans[s[i] - 1] = c[i];
  }
  if (N != 1 && ans[0] == 0) {
    cout << -1 << endl;
    exit(0);
  }
  if (N == 3 && ans[1] == 0) ans[2] = 1;
  int a = 0;
  for (int i = 0; i < N; i++) {
    if (ans[i] != -1) a += ans[i];
    a *= 10;
  }
  cout << a / 10 << endl;
  return 0;
}
