#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; ++i) {
    cin >> s[i] >> c[i];
  }
  int str[N];
  memset(str, -1, sizeof(str));
  for (int i = 0; i < M; ++i) {
    if (str[s[i] - 1] == -1) {
      str[s[i] - 1] = c[i];
      continue;
    }
    if (str[s[i]] > c[i]) str[s[i] - 1] = c[i];
  }
  int start = -1;
  int end = -1;
  for (int i = 0; i < M; ++i) {
    if (start != -1 && end != -1) break;
    if (start == -1 && str[i] != -1) start = i;
    if (end == -1 && str[M - i] != -1) end = M - i;
  }
  if (N != (end - start)) {
    printf("-1");
    return 0;
  }
  char result[N];
  for (int i = 0; i < N; ++i) {
    int t = str[start + i];
    result[i] = (t == -1 ? 0 : t) + '0';
  }
  printf("%s", result);
}
