#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const long long MOD = 1e9 + 7;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
  return is;
}
template <class T>
void print(const vector<T> &v, const string &delimiter) {
  for (int i = 0; i < (int)(v.size()); i++)
    cout << (0 < i ? delimiter : "") << v.at(i);
  cout << endl;
}
template <class T>
void print(const vector<vector<T>> &vv, const string &delimiter) {
  for (const auto &v : vv) print(v, delimiter);
}
int main() {
  int n, m;
  cin >> n >> m;
  string ans(n, '0');
  vector<bool> done(n);
  for (int i = 0; i < (int)(m); i++) {
    int s;
    char c;
    cin >> s >> c;
    s--;
    if (done.at(s) && ans.at(s) != c) {
      cout << -1 << endl;
      return 0;
    }
    ans.at(s) = c;
    done.at(s) = true;
  }
  if (n == 1)
    cout << ans << endl;
  else if (ans.at(0) == '0')
    cout << -1 << endl;
  else
    cout << ans << endl;
}
