#include <bits/stdc++.h>
using namespace std;
int n, m, tmp, jd = 1, digit;
std::vector<pair<int, int> > num;
void solve() {
  sort(num.begin(), num.end());
  reverse(num.begin(), num.end());
  for (int i = 0; i < (int)(m); i++) {
    if (num.at(i).first == 1 && num.at(i).second == 0) {
      jd = 0;
    }
  }
  for (int i = 0; i < (int)(m - 1); i++) {
    if (num.at(i).first == num.at(i + 1).first &&
        num.at(i).second != num.at(i + 1).second) {
      jd = 0;
    }
  }
  if (jd == 0) {
    cout << "-1" << endl;
    return;
  }
  std::vector<int> data(num.at(0).first);
  for (int i = 0; i < (int)(m); i++) {
    data.at(num.at(i).first - 1) = num.at(i).second;
  }
  for (int i = 0; i < (int)(data.size()); i++) {
    cout << data.at(i);
  }
  cout << endl;
  return;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < (int)(m); i++) {
    num.push_back(pair<int, int>());
    cin >> tmp;
    num.at(i).first = tmp;
    cin >> tmp;
    num.at(i).second = tmp;
  }
  solve();
  return 0;
}
