#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> query(m);
  for (int i = 0; i < m; i++) cin >> query[i].first >> query[i].second;
  auto solve = [&]() {
    int f = pow(10l, n - 1);
    int t = pow(10l, n) - 1;
    for (int i = f; i <= t; i++) {
      bool ok = true;
      for (auto q : query) {
        auto s = q.first;
        auto c = q.second;
        auto num = i;
        while (s < n) num /= 10, s++;
        if (num % 10 != c) {
          ok = false;
          break;
        }
      }
      if (ok) return i;
    }
    return -1;
  };
  cout << solve() << endl;
  return 0;
}
