#include <bits/stdc++.h>
using namespace std;
int a, b;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
int main() {
  long long n, m;
  string s = "0";
  cin >> n >> m;
  vector<pair<int, string>> v(m);
  for (int i = (0); i < (m); ++i) {
    cin >> v[i].first >> v[i].second;
  }
  for (int i = (0); i < (n - 1); ++i) {
    s += "0";
  }
  for (int i = (0); i < (m); ++i) {
    if (s[v[i].first - 1] == '0' || s[v[i].first - 1] == v[i].second[0]) {
      s.replace(v[i].first - 1, 1, v[i].second);
    } else
      s = "-1";
  }
  if (s[0] == '0' && n != 1) s = "-1";
  cout << s << endl;
  return 0;
}
