#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> integers, next;
  for (int i = (int)pow(10, n - 1); i < pow(10, n); ++i) integers.push_back(i);
  int s;
  char c;
  for (int i = 0; i < m; ++i) {
    cin >> s >> c;
    for (int j = 0; j < integers.size(); ++j) {
      if (to_string(integers[j])[s - 1] == c) {
        next.push_back(integers[j]);
      }
    }
    integers.clear();
    for (int j = 0; j < next.size(); ++j) {
      integers.push_back(next[j]);
    }
    next.clear();
  }
  if (integers.size() == 0) {
    cout << -1 << '\n';
    return 0;
  }
  sort(integers.begin(), integers.end());
  cout << integers[0] << '\n';
  return 0;
}
