#include <bits/stdc++.h>
int main(void) {
  int n;
  int m;
  int i, j;
  scanf("%d", &n);
  scanf("%d", &m);
  int s[m];
  int c[m];
  int temp[m];
  char num[n];
  for (i = 0; i < n; ++i) num[i] = '0';
  for (i = 0; i < m; ++i) {
    scanf("%d", &s[i]);
    scanf("%d", &c[i]);
    if (s[i] == 1 && c[i] == 0) {
      puts("-1");
      return 0;
    }
    temp[m] = s[i];
    for (j = 0; j < i; ++j) {
      if (s[i] == temp[j] && c[i] != c[j]) {
        puts("-1");
        return 0;
      }
    }
  }
  for (i = 0; i < m; ++i) switch (c[i]) {
      case 0:
        num[s[i] - 1] = '0';
        break;
      case 1:
        num[s[i] - 1] = '1';
        break;
      case 2:
        num[s[i] - 1] = '2';
        break;
      case 3:
        num[s[i] - 1] = '3';
        break;
      case 4:
        num[s[i] - 1] = '4';
        break;
      case 5:
        num[s[i] - 1] = '5';
        break;
      case 6:
        num[s[i] - 1] = '6';
        break;
      case 7:
        num[s[i] - 1] = '7';
        break;
      case 8:
        num[s[i] - 1] = '8';
        break;
      case 9:
        num[s[i] - 1] = '9';
        break;
    }
  if (num[0] == 0) num[0] = '1';
  printf(num);
  return 0;
}
