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