#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll PowMod(ll N, ll P, ll M) {
  if (P == 0) return 1;
  if (P % 2 == 0) {
    ll t = PowMod(N, P / 2, M);
    return (t % M) * (t % M);
  }
  return N * PowMod(N, P - 1, M) % M;
}
int main() {
  int digit = 1;
  int d = 1;
  int N, M;
  cin >> N >> M;
  vector<int> S(M), C(M);
  for (int i = 0; i < (int)(M); i++) {
    cin >> S.at(i) >> C.at(i);
  }
  vector<int> R(3, -2);
  int ret = 0;
  for (int i = 0; i < (int)(M); i++) {
    if (R.at(S.at(i) - 1) == -2) {
      R.at(S.at(i) - 1) = C.at(i);
    } else {
      if (R.at(S.at(i) - 1) != C.at(i)) {
        ret = -1;
        goto OUTPUT;
      }
    }
  }
  if (R.at(0) != -2) {
    digit = 3;
    if (R.at(1) == -2) {
      R.at(1) = 0;
    }
    if (R.at(2) == -2) {
      R.at(2) = 0;
    }
  } else if (R.at(1) != -2) {
    digit = 2;
    if (R.at(2) == -2) {
      R.at(2) = 0;
    }
  }
  if (digit = 3) {
    if (R.at(0) == 0) {
      ret = -1;
      goto OUTPUT;
    }
  } else if (digit == 2) {
    if (R.at(1) == 0) {
      ret = -1;
      goto OUTPUT;
    }
  }
  for (int i = 0; i < (int)(digit); i++) {
    ret += R.at(2 - i) * d;
    d *= 10;
  }
OUTPUT:
  cout << ret << endl;
}
