#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  if (N == 1 && M == 0) {
    printf("0");
    return 0;
  }
  int a, b;
  int ans[N];
  for (int i = 0; i < N; i++) {
    ans[i] = 99;
  }
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    if (ans[a - 1] == 99) {
      ans[a - 1] = b;
    } else if (ans[a - 1] == b) {
    } else {
      printf("-1");
      return 0;
    }
  }
  if (ans[0] == 99) {
    ans[0] = 1;
  } else if (ans[0] == 0) {
    printf("-1");
    return 0;
  }
  for (int i = 0; i < N; i++) {
    if (ans[i] == 99) {
      ans[i] = 0;
    }
  }
  if (N == 1 && ans[0] == 0) {
    printf("0");
    return 0;
  }
  for (int i = 0; i < N; i++) {
    printf("%d", ans[i]);
  }
  return 0;
}
