#include <bits/stdc++.h>
using namespace std;
int n, m;
struct f {
  int l, r;
} a[15];
int cmp(f x, f y) { return x.l < y.l; }
int p() {
  for (int i = 1; i < m; i++)
    if (a[i].l == a[i - 1].l && a[i].r != a[i - 1].r) return 0;
  return 1;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) scanf("%d%d", &a[i].l, &a[i].r);
  sort(a, a + m, cmp);
  int ans[5], sum = 0;
  memset(ans, 0, sizeof(ans));
  if (p() == 0)
    cout << "-1" << endl;
  else {
    for (int i = 0; i < m; i++) {
      ans[a[i].l] = a[i].r;
    }
    if (n > 1 && ans[1] == 0)
      cout << "-1" << endl;
    else {
      for (int i = 1; i <= m; i++) sum = sum * 10 + ans[i];
      cout << sum << endl;
    }
  }
  return 0;
}
