#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> a(M);
  for (long long i = 0; i < (M); i++) {
    long long b, c;
    cin >> b >> c;
    a[i] = 10 * b + c;
  }
  bool answer = true;
  sort((a).begin(), (a).end());
  for (long long j = 0; j < (M); j++) {
    for (long long i = 0; i < (M); i++) {
      if (a[i] / 10 == a[j] / 10) {
        if (a[i] % 10 != a[j] % 10) {
          answer = false;
        }
      }
    }
  }
  if (N != 1 && a[0] == 10) {
    answer = false;
  }
  if (answer) {
    long long sum = 0;
    for (long long i = 0; i < (M); i++) {
      if (a[i] / 10 == 1) {
        sum += (a[i] % 10) * pow(10, N - 1);
        break;
      }
    }
    for (long long i = 0; i < (M); i++) {
      if (a[i] / 10 == 2) {
        sum += (a[i] % 10) * pow(10, N - 2);
        break;
      }
    }
    for (long long i = 0; i < (M); i++) {
      if (a[i] / 10 == 3) {
        sum += (a[i] % 10) * pow(10, N - 3);
        break;
      }
    }
    cout << sum << endl;
  } else {
    cout << -1 << endl;
  }
}
