#include <bits/stdc++.h>
using namespace std;
char s[100];
int vis[100];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) s[i] = '0';
  int flag = 1;
  for (int i = 0; i < m; i++) {
    int pos, num;
    scanf("%d %d", &pos, &num);
    if (!vis[pos]) {
      vis[pos] = 1;
    } else {
      if (num + '0' != s[pos]) {
        flag = 0;
      }
    }
    s[pos] = num + '0';
  }
  s[n + 1] = '\0';
  for (int i = 1; i <= n; i++) {
    if (s[i] != '0') break;
    if (!vis[i]) s[i] = '1';
  }
  int num = atoi(s + 1);
  int temp = num;
  int len = 0;
  if (temp == 0) len = 1;
  while (temp) {
    temp /= 10;
    len++;
  }
  if (!flag || len != n) {
    printf("-1\n");
  } else {
    printf("%d\n", num);
  }
  return 0;
}
