#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  if (N == 1) {
    bool flag = true;
    for (int i = 0; i < M; i++) {
      for (int j = 0; j < M; j++) {
        if (c[i] != c[j]) flag = false;
      }
    }
    cout << (flag ? c[0] : -1) << endl;
  } else {
    vector<int> d(N, -1);
    int ans;
    bool flag1 = true, flag2 = true;
    for (int i = 0; i < M; i++) {
      if (d[s[i] - 1] == -1 || d[s[i] - 1] == c[i])
        d[s[i] - 1] = c[i];
      else
        flag1 = false;
      if (s[i] == 1 && c[i] == 0) flag2 = false;
    }
    if (flag1 && flag2) {
      ans = max(1, d[0]);
      for (int i = 1; i < N; i++) {
        ans *= 10;
        ans += max(0, d[i]);
      }
      cout << ans << endl;
    } else
      cout << -1 << endl;
  }
  return 0;
}
