#include <bits/stdc++.h>
int main(void) {
  int n, m, s, c, ans = 0;
  int d[3] = {10, 10, 10};
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &s, &c);
    if (d[s - 1] == 10)
      d[s - 1] = c;
    else if (d[s - 1] != c) {
      ans = -1;
      break;
    }
  }
  if (d[0] == 0) ans = -1;
  if (ans == 0) {
    if (d[0] == 10) d[0] = 1;
    if (d[1] == 10) d[1] = 0;
    if (d[2] == 10) d[2] = 0;
    for (int i = 0; i < n; i++) {
      ans *= 10;
      ans += d[i];
    }
  }
  printf("%d", ans);
  return 0;
}
