#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  int mn = 1;
  for (int i = 0; i < n - 1; ++i) mn *= 10;
  vector<pair<int, int> > v(m);
  for (int i = 0; i < m; ++i) cin >> v[i].first >> v[i].second;
  for (int i = 0; i < 1000; ++i) {
    bool val = 1;
    for (pair<int, int> p : v) {
      if (p.first == 1) {
        val &= p.second == i / 100;
      } else if (p.first == 2) {
        val &= p.second == i / 10 % 10;
      } else if (p.first == 3) {
        val &= p.second == i % 10;
      }
    }
    val &= (i >= mn || i == 0 && n == 1);
    if (val) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
}
