#include <bits/stdc++.h>
const double PI = 3.141592;
const int MOD = static_cast<int>(1e9) + 7;
using namespace std;
void solve() {
  int n, m, ans = -1;
  cin >> n >> m;
  vector<pair<int, int>> sc(m);
  for (int i = 0; i < m; ++i) {
    cin >> sc[i].first >> sc[i].second;
  }
  int max = 1;
  for (int i = 0; i < n; ++i) max *= 10;
  int st = max / 10;
  bool ok = true;
  for (int i = st; i < max; ++i) {
    string num = to_string(i);
    for (auto cond : sc) {
      string sec = to_string(cond.second);
      if (num.size() < (size_t)cond.first) {
        ok = false;
        continue;
      }
      if (num[cond.first - 1] != sec[0]) ok = false;
    }
    if (ok) {
      ans = i;
      break;
    }
    ok = true;
  }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
