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