#include <bits/stdc++.h>
using namespace std;
struct node {
  int s, c;
} b[6];
int n, m, ans, a[4];
bool cmp(node x, node y) { return x.c > y.c; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &b[i].s, &b[i].c);
  }
  sort(b + 1, b + n + 1, cmp);
  for (int i = 1; i <= m; i++) {
    if (b[i].s == 1 && b[i].c == 0)
      continue;
    else
      a[b[i].s] = b[i].c;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] != 0 || (i != 1 && a[i] == 0)) ans++;
  }
  if (n == 1 && a[1] == 0) {
    printf("0\n");
    return 0;
  } else {
    if (ans < n)
      printf("-1\n");
    else {
      for (int i = 1; i <= n; i++) printf("%d", a[i]);
      printf("\n");
    }
  }
  return 0;
}
