#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  return ret;
}
int execute() {
  int n, m;
  cin >> n >> m;
  string s = "";
  for (long long i = 0; i < n; i++) s += '0';
  for (long long i = 0; i < m; i++) {
    int a;
    char b;
    cin >> a >> b;
    if (s[a - 1] != '0' and s[a - 1] != b) {
      cout << -1 << endl;
      return 0;
    }
    s[a - 1] = b;
  }
  if (s[0] == '0') {
    cout << -1 << endl;
  } else {
    cout << s << endl;
  }
  return 0;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  execute();
  return 0;
}
