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