#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 pM, const int slist[], const int clist[],
                       const string pNumStr) {
  for (int i = 0, i_len = (pM); i < i_len; ++i) {
    if (pNumStr[slist[i] - 1] != (char)(clist[i] + '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 clist[5] = {0, 0, 0, 0, 0};
  int slist[5] = {0, 0, 0, 0, 0};
  bool no_exists = false;
  for (int i = 0, i_len = (m); i < i_len; ++i) {
    cin >> slist[i] >> clist[i];
    assert(slist[i] >= 1 && slist[i] <= n);
    assert(clist[i] >= 0 && clist[i] <= 9);
  }
  int answer = -1;
  if (no_exists) {
    cout << answer << endl;
    return 0;
  }
  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, slist, clist, str)) {
      answer = i;
      break;
    }
  }
  cout << answer << endl;
  return 0;
}
