#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 10;
int main() {
  int n, m;
  cin >> n >> m;
  int a[10] = {0};
  int f = 0;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (a[x] == 0)
      a[x] = y;
    else if (a[x] != y) {
      f = 1;
    }
  }
  if (n != 1 && a[1] == 0) f = 1;
  if (f == 1) {
    printf("-1\n");
    return 0;
  }
  printf("%d%d%d\n", a[1], a[2], a[3]);
}
