#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1000000007;
long long gcd(long long a, long long b) {
  int64_t gcdmax = max(a, b);
  int64_t gcdmin = min(a, b);
  while (true) {
    if (gcdmax % gcdmin == 0)
      break;
    else
      gcdmax %= gcdmin;
    do {
      int64_t c = gcdmin;
      gcdmin = gcdmax;
      gcdmax = c;
    } while (0);
  }
  return gcdmin;
}
int64_t powerup(int64_t N, int64_t P, int64_t M) {
  if (P == 0)
    return 1;
  else if (P % 2 == 0) {
    int64_t t = powerup(N, P / 2, M);
    return t * t % M;
  } else
    return N * powerup(N, P - 1, M) % M;
}
int main() {
  int64_t N, M;
  cin >> N >> M;
  int64_t A[5] = {0};
  int64_t tf = 1;
  int64_t n, m;
  for (int64_t i = 0; i < (int64_t)(M); i++) {
    cin >> n;
    cin >> m;
    if (A[n] == 0) {
      A[n] = m;
      if (n == 1 && A[n] == 0) tf = 0;
    } else if (m != A[n]) {
      cin >> A[n];
      tf = 0;
    }
  }
  if (tf == 0)
    cout << -1 << endl;
  else {
    for (int64_t i = 0; i < (int64_t)(N); i++) {
      if (i == 0 && A[1] == 0)
        cout << 1;
      else
        cout << A[i + 1];
    }
  }
}
