#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long N, M;
  cin >> N >> M;
  bool M_answer = true;
  if (M == 0) {
    M_answer = false;
  }
  if (M_answer) {
    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;
        }
      }
      if (N != 1 && sum < pow(10, N - 1)) {
        sum += pow(10, N - 1);
      }
      cout << sum << endl;
    } else {
      cout << -1 << endl;
    }
  } else {
    cout << pow(10, N - 1);
  }
}
