#include <bits/stdc++.h>
using namespace std;
string reverseStr(string);
int main() {
  int N, M;
  cin >> N >> M;
  bool isValid = true;
  int s, sTemp;
  char c, cTemp;
  string strN(N, '0');
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    strN[(s - 1)] = c;
    if ((s == sTemp) && (c != cTemp)) {
      isValid = false;
    }
    cTemp = c;
    sTemp = s;
  }
  if ((strN[0] == '0') && strN.size() > 1) {
    isValid = false;
  }
  if (!isValid) {
    strN = "-1";
  }
  cout << stoi(strN) << endl;
}
