#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, d[7], s, c, ans = 1;
  memset(d, 0, sizeof(d));
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &s, &c);
    if (d[s] != 0 && d[s] != c) ans = 0;
    d[s] = c;
  }
  if (d[1] == 0) d[1] = 1;
  if (ans) {
    for (int i = 1; i <= m; i++) printf("%d", d[i]);
    printf("\n");
  } else
    printf("-1\n");
  return 0;
}
