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