#include <bits/stdc++.h>
using namespace std;
long long n, m;
map<long long, long long> mp;
signed main() {
  cin >> n >> m;
  for (long long i = (0); i < (m); ++i) {
    long long c, m;
    cin >> c >> m;
    if (mp.count(c) != 0) {
      if (mp[c] != m) {
        std::cout << -1 << endl;
        return 0;
      }
    }
    mp[c] = m;
  }
  long long res = 0;
  for (auto m : mp) {
    res += pow(10, n - m.first) * m.second;
  }
  if (res / pow(10, n - 1)) {
    std::cout << res << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
