#include <bits/stdc++.h>
using namespace std;
namespace math {
long double PI = 3.14159265359;
long long step(long long n);
long long ncr(long long n, long long r);
long long npr(long long n, long long r);
long long gcm(long long a, long long b);
long long lcm(long long a, long long b);
long long step(long long n) {
  if (n <= 1) {
    return 1;
  } else {
    return n * step(n - 1);
  }
}
long long ncr(long long n, long long r) {
  for (long long i = 1; i < r; i++) {
    n *= n - i;
  }
  for (long long i = 1; i < r; i++) {
    r *= r - 1;
  }
  return n / r;
}
long long npr(long long n, long long r) {
  for (long long i = 1; i < r; ++i) {
    n *= n - 1;
  }
  return n;
}
long long gcm(long long a, long long b) {
  long long p = max(a, b);
  long long q = min(a, b);
  long long r;
  while (true) {
    if (p % q == 0) {
      return q;
    }
    r = p % q;
    p = q;
    q = r;
  }
}
}  // namespace math
using namespace std;
long long f = 0;
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<char> S(n, '0');
  for (long long i = 0; i < m; i++) {
    long long s;
    char c;
    cin >> s >> c;
    if (S[s - 1] == '0') {
      S[s - 1] = c;
    } else {
      if (S[s - 1] != c) {
        f++;
        break;
      }
    }
  }
  if (f == 1) {
    cout << -1 << endl;
  }
  long long flag = 0;
  for (long long i = 0; i < n; i++) {
    if (flag == 0 && S[i] != '0') {
      flag = 1;
      cout << S[i];
    } else if (flag != 0) {
      cout << S[i];
    }
  }
  cout << '\n';
  if (flag == 0) {
    cout << -1 << endl;
  }
  return 0;
}
