#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, ansF, cou;
  cin >> N >> M;
  ansF = cou = 0;
  int ans[N], s[M], c[M];
  for (int i = 0; i < (N); ++i) ans[i] = 0;
  for (int i = 0; i < (M); ++i) cin >> s[i] >> c[i];
  for (int i = 0; i < M; ++i) {
    ans[s[i] - 1] = c[i];
    for (int j = 0; j < i; ++j) {
      if (s[i] == s[j]) {
        if (c[i] != c[j]) {
          cou = 1;
        }
      }
    }
  }
  if (cou == 1) {
    ansF = -1;
  } else {
    ansF = 0;
    for (int i = 0; i < N; ++i) {
      int tmp = 0;
      if (i == 2) {
        tmp = 1;
      } else if (i == 1) {
        tmp = 10;
      } else {
        tmp = 100;
      }
      ansF += ans[i] * tmp;
    }
  }
  if (N == 1 && ansF > 9) {
    cou = 1;
  } else if (N == 2 && (ansF < 10 || ansF > 99)) {
    cou = 1;
  } else if (N == 3 && (ansF < 100 || ansF > 999)) {
    cou = 1;
  }
  if (cou == 1) {
    ansF = -1;
  }
  printf("%d\n", ansF);
  return 0;
}
