#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, m;
  cin >> N >> m;
  string S = "";
  for (int i = 0; i < N; i++) {
    if (i == 0)
      S += '1';
    else
      S += '0';
  }
  map<int, char> M;
  bool ans = true;
  for (int i = 0; i < m; i++) {
    int s;
    char c;
    cin >> s >> c;
    if (!M.count(s))
      M[s] = c;
    else if (M.at(s) != c) {
      ans = false;
      break;
    }
  }
  if (!ans)
    cout << -1 << endl;
  else {
    for (auto p : M) {
      auto k = p.first;
      auto v = p.second;
      S.at(k) = M.at(k);
    }
    if (S.at(0) == '0')
      cout << -1 << endl;
    else
      cout << S << endl;
  }
  return 0;
}
