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