#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  string ans = "";
  for (int i = 0; i < (int)(n); ++i) {
    ans += "0";
  }
  for (int i = 0; i < (int)(m); ++i) {
    int s;
    char c;
    cin >> s >> c;
    if (ans[s - 1] == '0' || ans[s - 1] == c) {
      ans[s - 1] = c;
    } else {
      ans = "-1";
      break;
    }
  }
  if (ans[0] == '0') ans = "-1";
  cout << ans << endl;
}
