#include <bits/stdc++.h>
using namespace std;
signed main() {
  int N, M;
  cin >> N >> M;
  int s[10];
  int c[10];
  for (int i = 0; i < (int)(M); i++) {
    cin >> s[i];
    cin >> c[i];
  }
  bool res = true;
  for (int i = 0; i < (int)(M); i++) {
    if (N < s[i]) res = false;
  }
  int R[4] = {-1, -1, -1, -1};
  for (int i = 0; i < (int)(M); i++) {
    if ((R[s[i]] != -1) && (R[s[i]] != c[i])) {
      res = false;
      break;
    }
    R[s[i]] = c[i];
  }
  if ((N == 3) && (R[1] == -1)) res = false;
  if ((N == 3) && (R[1] == 0)) res = false;
  if ((N == 2) && (R[1] == -1)) res = false;
  if ((N == 2) && (R[1] == 0)) res = false;
  for (int i = 0; i < (int)(M); i++) {
    if (R[i + 1] == -1) R[i + 1] = 0;
  }
  int num = 0;
  if (N == 1)
    num = R[1];
  else if (N == 2)
    num = R[2] + (R[1] * 10);
  else if (N == 3)
    num = R[3] + (R[2] * 10) + (R[1] * 100);
  else
    ;
  if (false == res) {
    cout << -1 << endl;
  } else {
    cout << num << endl;
  }
}
