#include <bits/stdc++.h>
using namespace std;
int n, m, s, c, ans, a[4];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 3; i++) a[i] = 15;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &s, &c);
    if (a[s] > c && c != 0) a[s] = c;
  }
  for (int i = 1; i <= 3; i++)
    if (a[i] == 15) a[i] = 0;
  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;
}
