#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int a[3] = {-1, -1, -1};
  int out = 0;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 0)
      break;
    else if (a[s - 1] == -1 || a[s - 1] == c)
      a[s - 1] = c;
    else {
      out = -1;
      break;
    }
  }
  if ((N == 3 && a[0] == 0) || (N == 2 && a[1] == 0)) out = -1;
  if (out != -1) {
    if (N == 3) {
      if (a[0] == -1) a[0] = 1;
      if (a[1] == -1) a[1] = 0;
      if (a[2] == -1) a[2] = 0;
    }
    if (N == 2) {
      if (a[0] == -1) a[0] = 0;
      if (a[1] == -1) a[1] = 1;
      if (a[2] == -1) a[2] = 0;
    }
    if (N == 1) {
      if (a[0] == -1) a[0] = 0;
      if (a[1] == -1) a[1] = 0;
      if (a[2] == -1) a[2] = 0;
    }
    out = a[0] * 100 + a[1] * 10 + a[2];
  }
  cout << out << endl;
  return 0;
}
