#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  int a[N];
  for (int i = 0; i < N; i++) {
    a[i] = -1;
  }
  int s, c, ans;
  ans = 0;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (a[s - 1] == -1 || a[s - 1] == c) {
      a[s - 1] = c;
    } else {
      ans = -1;
      break;
    }
  }
  if (ans == 0) {
    ans = a[0] * pow(10, N - 1);
    for (int i = 1; i < N; i++) {
      ans += max(0, a[i]) * pow(10, N - i - 1);
    }
    if (N > 1 && a[0] == 0) ans = -1;
  }
  cout << ans << endl;
}
