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