#include <bits/stdc++.h>
using namespace std;
int solve(int n) {
  int qtd = 0;
  if (n == 0) return 1;
  while (n) {
    qtd++;
    n /= 10;
  }
  return qtd;
}
int vs[4];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < 4; i++) {
    vs[i] = -1;
  }
  int n, m, aux, d;
  bool t = true, o = false;
  cin >> n >> m;
  while (m--) {
    cin >> aux >> d;
    if (vs[aux - 1] != -1 and vs[aux - 1] != d)
      t = false;
    else
      vs[aux - 1] = d;
  }
  if (vs[0] == -1 and n == 1) {
    cout << "0" << endl;
  }
  if (t) {
    aux = 1;
    d = 0;
    if (vs[0] == -1) vs[0] = 1;
    for (int i = n - 1; i > -1; i--) {
      if (vs[i] != -1)
        d += aux * vs[i];
      else {
        d += aux * 0;
      }
      aux *= 10;
    }
    if (n != solve(d)) d = -1;
  } else {
    d = -1;
  }
  cout << d << endl;
  return 0;
}
