#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> sc;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (sc[a] && sc[a] != b) {
      cout << -1 << '\n';
      return 0;
    }
    sc[a] = b;
  }
  if (sc.count(1) && !sc[1] && n > 1) {
    cout << -1 << '\n';
    return 0;
  }
  string S;
  for (int i = 0; i < n; ++i) {
    int i_ = i + 1;
    int v = sc.size();
    if (v) {
      S += sc[i_] + '0';
      sc.erase(i_);
    }
  }
  int ans = 0;
  if (S.size()) {
    if (S[0] == '0') {
      S[0] = '1';
    }
    ans = stoi(S);
  }
  cout << ans << '\n';
}
