#include <bits/stdc++.h>
int main() {
  using namespace std;
  unsigned long N, M;
  cin >> N >> M;
  unsigned long i{0}, j{0};
  if (N == 1) j = (i = 1) * 10;
  if (N == 2) j = (i = 10) * 10;
  if (N == 3) j = (i = 100) * 10;
  vector<pair<unsigned long, char>> g(M);
  for (auto& h : g) cin >> h.first >> h.second;
  for (; i < j; ++i) {
    string s{to_string(i)};
    [&] {
      for (const auto& k : g)
        if (s[k.first - 1] != k.second) return;
      cout << i << endl;
      exit(0);
    }();
  }
  puts("-1");
  return 0;
}
