#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<pair<long long, long long> > v(5);
signed main() {
  cin >> n >> m;
  v.resize(m);
  for (long long i = (0); i < (n); ++i) {
    cin >> v[i].first >> v[i].second;
  }
  for (long long i = (pow(10, n - 1)); i < (pow(10, n)); ++i) {
    string s = to_string(i);
    bool flag = true;
    for (auto pa : v) {
      if (s[pa.first - 1] != pa.second + '0') {
        flag = false;
      }
    }
    if (flag) {
      cout << s << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
