#include <bits/stdc++.h>
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;
int main(int argc, const char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64_t n, m;
  cin >> n >> m;
  vi s(m), c(m);
  for (int64_t i = 0; i < (int64_t)(m); i++) cin >> s.at(i) >> c.at(i);
  int64_t res = -1;
  vi num(n, 10);
  bool result = true;
  for (int64_t i = 0; i < (int64_t)(m); i++) {
    if (num.at(s.at(i) - 1) == 10 || num.at(s.at(i) - 1) == c.at(i)) {
      num.at(s.at(i) - 1) = c.at(i);
    } else {
      result = false;
      break;
    }
  }
  if (n != 1 && num.at(0) == 0) result = false;
  vi resNum(n);
  if (result) {
    for (int64_t i = 0; i < (int64_t)(n); i++) {
      if (num.at(i) != 10) {
        resNum.at(i) = num.at(i);
      } else {
        resNum.at(i) = 0;
      }
    }
    string resStr = "";
    for (int64_t i = 0; i < (int64_t)(n); i++) {
      resStr += to_string(resNum.at(i));
    }
    res = stoll(resStr);
    if (n == 1 && num.at(0) == 0) res = 0;
  }
  cout << res << endl;
}
