#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  string result = "";
  for (int i = 0; i < N; ++i) {
    result += "0";
  }
  vector<bool> flgs(10, false);
  bool flg = false;
  for (int i = 0; i < M; ++i) {
    int si;
    char ci;
    cin >> si >> ci;
    if ((flgs.at(si) && result.at(si - 1) != ci) ||
        (si == 1 && ci == '0' && N != 1)) {
      flg = true;
      break;
    }
    flgs.at(si) = true;
    result.at(si - 1) = ci;
  }
  if (flg) {
    cout << -1 << endl;
  } else {
    if (result.at(0) == '0') {
      result.at(0) = '1';
    }
    cout << result << endl;
  }
}
