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