#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
template <typename T>
T lcm(T a, T b) {
  return a / __gcd(a, b) * b;
}
int main() {
  int n, m;
  cin >> n >> m;
  map<int, char> _map;
  bool is_not_exist = false;
  for (int i = 0; i < (int)m; i++) {
    int a;
    char x;
    cin >> a >> x;
    if (_map.count(a)) {
      if (_map[a] != x) is_not_exist = true;
    }
    _map[a] = x;
  }
  deque<char> ans;
  for (int i = 1; i < (int)n + 1; i++) {
    if (_map.count(i)) {
      ans.push_back(_map[i]);
    } else {
      ans.push_back('0');
    }
  }
  if (ans.front() == '0') {
    cout << -1 << endl;
    return 0;
  }
  while (!ans.empty()) {
    cout << ans.front();
    ans.pop_front();
  }
  cout << endl;
  return 0;
}
