#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int number[n];
  for (int i = 0; i < n; i++) {
    number[i] = -1;
  }
  int s, c;
  bool flag = true;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (c != number[s - 1] and number[s - 1] != -1) {
      flag = false;
      break;
    } else if (number[s - 1] == -1) {
      if (s == 1 and c == 0) {
        flag = false;
        break;
      }
      number[s - 1] = c;
    } else if (c == number[s - 1] and number[s - 1] != -1) {
      if (s == 1 and c == 0) {
        flag = false;
        break;
      }
      number[s - 1] = c;
    }
  }
  if (flag == false) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (number[i] != -1) {
      printf("%d", number[i]);
    } else {
      printf("0");
    }
  }
  printf("\n");
  return 0;
}
