#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, m;
  cin >> n >> m;
  map<long long int, long long int> mp;
  bool f = true;
  for (long long int i = 0; i < m; i++) {
    long long int x, y;
    cin >> x >> y;
    x--;
    if (mp.count(x) && mp[x] != y) f = false;
    mp[x] = y;
  }
  if (!f) {
    cout << -1;
    return;
  }
  for (long long int i = 0; i < pow(10, n); i++) {
    string s = to_string(i);
    f = true;
    for (auto &x : mp) {
      if (x.first >= s.length() || (s[x.first] - '0') != x.second) f = false;
    }
    if (f) {
      cout << i;
      return;
    }
  }
  cout << -1;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t, c;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
