#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, char>> sc(M);
  rep(i, M) {
    int s;
    char c;
    cin >> s >> c;
    sc.at(i) = make_pair(s - 1, c);
  }

  for (const int num : boost::irange(100, 1000)) {
    string s = to_string(num);
    if (all_of(sc.begin(), sc.end(),
               [s](pair<int, char> p) { return s.at(p.first) == p.second; })) {
      cout << num << endl;
      return 0;
    }
  }

  cout << "-1" << endl;
  return 0;
}
