#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, char>> sc(M);
  for (int i = 0; i < (M); ++i) {
    int s;
    char c;
    cin >> s >> c;
    sc.at(i) = make_pair(s, c);
  }
  sort(sc.begin(), sc.end());
  string ans = "1";
  for (int i = 0; i < (N - 1); ++i) ans += '0';
  vector<bool> changed(N, false);
  for (int i = 0; i < (M); ++i) {
    int s = sc.at(i).first - 1;
    char c = sc.at(i).second;
    if (changed.at(s) && ans.at(s) != c) {
      cout << "-1" << endl;
      return 0;
    }
    changed.at(s) = true;
    ans.at(s) = c;
  }
  if (ans.at(0) == '0') ans = "-1";
  cout << ans << endl;
  return 0;
}
