#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double EPS = 1e-9;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
signed main(void) {
  long long n;
  cin >> n;
  vector<long long> ans(4, -1);
  if (n == 1) {
    long long m;
    cin >> m;
    for (long long i = 0; i < (m); i++) {
      long long ind, num;
      cin >> ind >> num;
      if (num == 0) {
        cout << -1 << endl;
        return 0;
      }
      if (ans[ind] != -1 && num != ans[ind]) {
        cout << -1 << endl;
        return 0;
      }
      ans[ind] = num;
    }
    if (ans[1] == -1) ans[1] = 1;
    cout << ans[1] << endl;
    return 0;
  }
  if (n == 2) {
    long long m;
    cin >> m;
    for (long long i = 0; i < (m); i++) {
      long long ind, num;
      cin >> ind >> num;
      if (ind == 1 && num == 0) {
        cout << -1 << endl;
        return 0;
      }
      if (ans[ind] != -1 && num != ans[ind]) {
        cout << -1 << endl;
        return 0;
      }
      ans[ind] = num;
    }
    if (ans[1] == -1) ans[1] = 1;
    if (ans[2] == -1) ans[2] = 0;
    cout << ans[1] << ans[2] << endl;
    return 0;
  }
  if (n == 3) {
    long long m;
    cin >> m;
    for (long long i = 0; i < (m); i++) {
      long long ind, num;
      cin >> ind >> num;
      if (ind == 1 && num == 0) {
        cout << -1 << endl;
        return 0;
      }
      if (ans[ind] != -1 && num != ans[ind]) {
        cout << -1 << endl;
        return 0;
      }
      ans[ind] = num;
    }
    if (ans[1] == -1) ans[1] = 1;
    if (ans[2] == -1) ans[2] = 0;
    if (ans[3] == -1) ans[3] = 0;
    cout << ans[1] << ans[2] << ans[3] << endl;
    return 0;
  }
}
