#include <bits/stdc++.h>
int s[10], c[10];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &s[i], &c[i]);
  }
  int cap = 1, ans = -1;
  for (int i = 0; i < n - 1; i++) cap *= 10;
  for (int i = cap; i < cap * 10; i++) {
    int ok = 1;
    for (int j = 0; j < m; j++) {
      int cur = i;
      for (int z = 0; z < n - s[j]; z++) {
        cur /= 10;
      }
      cur = cur % 10;
      if (cur != c[j]) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      ans = i;
      break;
    }
  }
  printf("%d\n", ans);
}
