#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  map<long long, long long> sc;
  long long ans = 0;
  for (long long i = 0; i < (long long)(m); i++) {
    long long s, c;
    cin >> s;
    cin >> c;
    if (sc.count(s) && sc.at(s) != c || n > 1 && s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    sc.emplace(s, c);
  }
  for (long long i = 1; i <= n; i++) {
    if (sc.count(i))
      ans += sc.at(i) * pow(10, n - i);
    else {
      if (i == 1) ans += pow(10, n - 1);
    }
  }
  cout << ans << endl;
}
