#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1 << 30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++)
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
void solve() {
  int n, m;
  cin >> n >> m;
  if (n == 1 and m == 0) cout << 0 << endl;
  map<int, set<char>> mp;
  for (int i = 0; i < m; i++) {
    int s;
    char c;
    cin >> s >> c;
    mp[s].insert(c);
  }
  bool ok = true;
  string ans = "";
  for (int i = 0; i < m; i++) {
    if (mp[i + 1].size() == 0) mp[i + 1].insert('0');
  }
  for (auto &x : mp) {
    if (x.second.size() >= 2) ok = false;
    set<char> st = x.second;
    ans += *st.begin();
  }
  if (ans.front() == '0' or ans.size() == 0) ok = false;
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
