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