#include <bits/stdc++.h>
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;
int64_t INF = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64_t n, m;
  cin >> n >> m;
  vi s(m), c(m);
  for (int64_t i = 0; i < (int64_t)(m); i++) cin >> s.at(i) >> c.at(i);
  vi candidate;
  vi filteredCandidate;
  if (n == 1) {
    for (int64_t i = 1; i < 10; i++) candidate.push_back(i);
    for (int64_t can : candidate) {
      bool res = true;
      for (int64_t j = 0; j < m; j++) {
        if (to_string(can).at(s.at(j)) != c.at(j)) res = false;
      }
      if (res) filteredCandidate.push_back(can);
    }
  }
  if (n == 2) {
    for (int64_t i = 10; i < 100; i++) candidate.push_back(i);
    for (int64_t can : candidate) {
      bool res = true;
      for (int64_t j = 0; j < m; j++) {
        if (to_string(can).at(s.at(j)) != c.at(j)) res = false;
      }
      if (res) filteredCandidate.push_back(can);
    }
  }
  if (n == 3) {
    for (int64_t i = 100; i < 1000; i++) candidate.push_back(i);
    for (int64_t can : candidate) {
      bool res = true;
      for (int64_t j = 0; j < m; j++) {
        if (to_string(can).at(s.at(j) - 1) != c.at(j) + 48) res = false;
      }
      if (res) filteredCandidate.push_back(can);
    }
  }
  cout << (filteredCandidate.empty() ? (-1) : filteredCandidate.at(0)) << endl;
}
