#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
bool check_constraints(const int pN, const int pConstraints[],
                       const string pNumStr) {
  for (int i = 0, i_len = (pN); i < i_len; ++i) {
    int i_val = (pConstraints[i] > -1) ? pConstraints[i] : 0;
    if (pNumStr[i] != (char)(i_val + '0')) {
      return false;
    }
  }
  return true;
}
int main() {
  int n = 0, m = -1;
  cin >> n >> m;
  assert(n >= 1 && n <= 3);
  assert(m >= 0 && m <= 5);
  int constraints[3] = {-1, -1, -1};
  bool no_exists = false;
  for (int i = 0, i_len = (m); i < i_len; ++i) {
    int s = 0, c = -1;
    cin >> s >> c;
    assert(s >= 1 && s <= n);
    assert(c >= 0 && c <= 9);
    if (constraints[s - 1] != -1 && constraints[s - 1] != c) {
      no_exists = true;
      break;
    }
    if (constraints[s - 1] == -1) {
      constraints[s - 1] = c;
    }
  }
  int answer = -1;
  if (no_exists) {
    cout << answer << endl;
    return 0;
  }
  if ((n > 1 && constraints[3 - n] != 0) || n == 1) {
    for (int i = 1, i_len = (1000); i <= i_len; ++i) {
      stringstream iss;
      iss << i;
      string str = iss.str();
      if (str.size() != n) continue;
      if (check_constraints(n, constraints, str)) {
        answer = i;
        break;
      }
    }
  }
  cout << answer << endl;
  return 0;
}
