#include <bits/stdc++.h>
void input(int *N, int *M, int *s, int *c);
void get2Num(int *, int *);
int iCalc(int *N, int *M, int *s, int *c);
int iPow(int a, int b);
int main() {
  int N, M, s[5], c[5];
  input(&N, &M, &s[0], &c[0]);
  int ans = iCalc(&N, &M, &s[0], &c[0]);
  printf("%d\n", ans);
  return 0;
}
void input(int *N, int *M, int *s, int *c) {
  get2Num(N, M);
  for (int i = 0; i < *M; i++) get2Num(&s[i], &c[i]);
  return;
}
void get2Num(int *a, int *b) {
  scanf("%d %d", a, b);
  return;
}
int iCalc(int *N, int *M, int *s, int *c) {
  bool bAlready[*N + 1];
  for (int i = 0; i < *N; i++) bAlready[i + 1] = false;
  int iRet = 0, digit, iVal[*N + 1];
  for (int i = 0; i < *M; i++) {
    if (s[i] == 1 && c[i] == 0 && *N != 1) return -1;
    if (!bAlready[s[i]]) {
      digit = *N - s[i];
      iRet += iPow(10, digit) * c[i];
      bAlready[s[i]] = true;
      iVal[s[i]] = c[i];
    } else if (iVal[s[i]] != c[i])
      return -1;
  }
  if (!bAlready[1] && *M != 0) iRet += iPow(10, *N - 1);
  return iRet;
}
int iPow(int a, int b) {
  int iRet = 1;
  for (int i = 0; i < b; i++) iRet *= a;
  if (b == 0) iRet = 1;
  return iRet;
}
