#include <bits/stdc++.h>
using namespace std;
struct X {
  int s, c;
} a[10];
int n, m, ans[5];
bool flag = true;
bool cmp(X x, X y) { return x.s < y.s; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &a[i].s, &a[i].c);
    if (a[i].c == 0 && a[i].s == 1) flag = false;
  }
  if (!flag) {
    printf("-1");
    return 0;
  }
  sort(a + 1, a + m + 1, cmp);
  for (int i = 1; i < m; ++i)
    if (a[i].s == a[i + 1].s && a[i].c != a[i + 1].c) {
      printf("-1");
      return 0;
    }
  for (int i = 1; i <= m; ++i) ans[a[i].s] = a[i].c;
  if (!ans[1] && n != 1) ans[1] = 1;
  for (int i = 1; i <= n; ++i) printf("%d", ans[i]);
  return 0;
}
