#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e6;
int a[10], c[10], s[10];
int n, m;
int main() {
  int flag = 0, cnt = -2;
  scanf("%d%d", &n, &m);
  memset(a, 0, sizeof(a));
  memset(c, 0, sizeof(c));
  if (m == 0) {
    flag = 1;
    cnt = 0;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &s[i], &c[i]);
    if (s[i] == 1 && n > 1 && c[i] == 0) {
      flag = 1;
      cnt = -1;
    } else {
      for (int j = 0; j < i; j++) {
        if (s[j] == s[i] && c[i] != c[j]) {
          flag = 1;
          cnt = -1;
        }
      }
    }
    a[s[i] - 1] = c[i];
  }
  if (n > 1 && a[0] == 0) a[0] = 1;
  if (cnt == -1 || cnt == 0) {
    printf("%d", cnt);
  }
  if (flag == 0) {
    for (int i = 0; i < n; i++) {
      printf("%d", a[i]);
    }
  }
  return 0;
}
