#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long N, M;
  cin >> N >> M;
  map<long long, long long> mp;
  bool flag = true;
  for (long long i = (0), i_len = (M); i < i_len; ++i) {
    long long s, c;
    cin >> s >> c;
    s--;
    if (mp.count(s) > 0 && mp[s] != c) {
      flag = false;
    }
    mp[s] = c;
    if (N >= 2 && s == 0 && c == 0) {
      flag = false;
    }
  }
  if (!flag) {
    cout << "-1\n";
  } else {
    for (long long i = (pow(10, N - 1)), i_len = (pow(10, N)); i < i_len; ++i) {
      flag = true;
      string s = to_string(i);
      for (auto &x : mp) {
        if (s[x.first] != '0' + x.second) {
          flag = false;
        }
      }
      if (flag) {
        cout << s << endl;
        break;
      }
    }
  }
  return 0;
}
