#include <bits/stdc++.h>
int Answer(int N, int M, int* s, int* c, int* Number);
int main(void) {
  int N = 0;
  int M = 0;
  scanf("%d %d", &N, &M);
  int* s = NULL;
  int* c = NULL;
  s = (int*)malloc(sizeof(int) * M);
  c = (int*)malloc(sizeof(int) * M);
  for (int ii = 0; ii < M; ii++) {
    scanf("%d %d", &s[ii], &c[ii]);
  }
  std::string str;
  int* Number = NULL;
  Number = (int*)malloc(sizeof(int) * N);
  for (int ii = 0; ii < N; ii++) {
    Number[ii] = -1;
  }
  int AnswerStatus = Answer(N, M, s, c, Number);
  if (AnswerStatus != 0) {
    std::cout << "-1";
  } else {
    for (int ii = 0; ii < N; ii++) {
      std::string tmpStr;
      tmpStr = std::to_string(Number[ii]);
      str = str + tmpStr;
    }
    std::cout << str;
  }
  if (Number != NULL) {
    free(Number);
  }
  if (c != NULL) {
    free(c);
  }
  if (s != NULL) {
    free(s);
  }
  return 0;
}
int Answer(int N, int M, int* s, int* c, int* Number) {
  int rc = 0;
  if (N <= 0) {
    rc = -1;
    return rc;
  }
  if (M <= 0) {
    rc = -1;
    return rc;
  }
  if (s == NULL) {
    rc = -1;
    return rc;
  }
  if (c == NULL) {
    rc = -1;
    return rc;
  }
  for (int ii = 0; ii < M; ii++) {
    int keta = 0;
    keta = s[ii];
    if ((Number[keta - 1] != -1) && (Number[keta - 1] != c[ii])) {
      rc = -1;
      break;
    } else {
      if ((Number[keta - 1] == -1) || (Number[keta - 1] > c[ii])) {
        Number[keta - 1] = c[ii];
      }
    }
  }
  for (int ii = 0; ii < N; ii++) {
    if (Number[ii] == -1) {
      if ((ii == 0) && (N == 1)) {
        Number[ii] = 1;
      } else {
        Number[ii] = 0;
      }
    }
  }
  if (Number[0] == 0) {
    rc = -1;
  }
  return rc;
}
