#include <bits/stdc++.h>
using namespace std;
int N, M;
int a[3] = {-1, -1, -1};
bool check(int n) {
  string s = to_string(n);
  if (s.length() != N) return false;
  for (int i = 0; i < s.length(); ++i) {
    if (a[i] == -1) {
      continue;
    } else if (s[i] - '0' != a[i]) {
      return false;
    }
  }
  return true;
}
bool check0() { return N == 1 and a[0] == 0 and a[1] == -1 and a[2] == -1; }
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int x, y;
    cin >> x >> y;
    x--;
    if (a[x] != -1 and a[x] != y) {
      cout << -1 << '\n';
      return 0;
    } else {
      a[x] = y;
    }
  }
  for (int i = 1; i < 1000; ++i) {
    if (check(i)) {
      cout << i << '\n';
      return 0;
    }
  }
  if (check0()) {
    cout << 0 << '\n';
  } else {
    cout << -1 << '\n';
  }
  return 0;
}
