#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, si, ci, ans;
  int c[6];
  scanf("%d %d", &N, &M);
  for (int i = 1; i <= N; i++) c[i] = -1;
  for (int i = 1; i <= M; i++) {
    scanf("%d %d", &si, &ci);
    if (c[si] == -1) {
      c[si] = ci;
    } else if (c[si] != ci) {
      printf("%d", -1);
      return 0;
    }
  }
  if (c[1] == 0) {
    printf("%d", -1);
    return 0;
  }
  ans = 0;
  for (int i = 1; i <= N; i++) {
    if (c[i] == -1) {
      ans *= 10;
    } else {
      ans = 10 * ans + c[i];
    }
  }
  printf("%d", ans);
}
