#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M), check(N, 0);
  bool failed = false;
  for (int i = 0; i < (M); i++) {
    cin >> s.at(i) >> c.at(i);
  }
  vector<int> ans(N);
  for (int i = 0; i < (M); i++) {
    if (check.at(s.at(i) - 1) == 1 && ans.at(s.at(i) - 1) != c.at(i)) {
      failed = true;
    }
    check.at(s.at(i) - 1) = 1;
    ans.at(s.at(i) - 1) = c.at(i);
  }
  if (failed) {
    cout << -1 << endl;
  } else if (N != 1 && ans.at(0) == 0) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < (N); i++) {
      cout << ans.at(i);
    }
    cout << endl;
  }
}
