#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& output, const pair<A, B>& p) {
  output << "(" << p.first << ", " << p.second << ")";
  return output;
}
template <class A>
ostream& operator<<(ostream& output, const vector<A>& a) {
  output << "[";
  for (auto it = a.begin(); it != a.end(); ++it) {
    if (it != a.begin()) {
      output << ", ";
    }
    output << *it;
  }
  output << "]";
  return output;
}
using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  string num(n, '0');
  for (int i = 0; i < m; ++i) {
    int s;
    char c;
    cin >> s >> c;
    if (num[s - 1] != '0') {
      num[s - 1] = min(num[s - 1], c);
    } else {
      num[s - 1] = c;
    }
  }
  if (n == 2 or n == 3) {
    if (num[0] == '0') {
      cout << -1 << "\n";
      return 0;
    }
  }
  cout << num << "\n";
  return 0;
}
