#include <bits/stdc++.h>
using namespace std;
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0) {
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}
uint64_t lcm(uint64_t m, uint64_t n) { return (m * n) / gcd(m, n); }
void comb(vector<vector<uint64_t> > &v) {
  for (uint64_t i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (uint64_t k = 1; k < v.size(); k++) {
    for (uint64_t j = 1; j < k; j++) {
      v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
    }
  }
}
bool is_product_overflow(uint64_t a, uint64_t b) {
  uint64_t prod = a * b;
  return (prod / b != a);
}
void primeFactorization(uint64_t a, list<uint64_t> &factors) {
  long i, sq;
  if (a % 2 == 0) {
    factors.push_back(2);
    primeFactorization(a / 2, factors);
    return;
  }
  sq = sqrt(a);
  for (i = 3; i <= sq; i += 2) {
    if (a % i == 0) {
      factors.push_back(i);
      primeFactorization(a / i, factors);
      return;
    }
  }
  if (a != 1) {
    factors.push_back(a);
  }
}
int64_t modinv(int64_t a, int64_t m) {
  int64_t b = m, u = 1, v = 0;
  while (b) {
    int64_t t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
signed main() {
  int n, m;
  cin >> n >> m;
  string numFlag;
  string num;
  for (int i = 0; i < n; i++) {
    num += "0";
    numFlag += "*";
  }
  int s;
  string c;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (numFlag[s - 1] != '*' && num[s - 1] != c[0]) {
      cout << "-1" << endl;
      return 0;
    }
    numFlag[s - 1] = c[0];
    num[s - 1] = c[0];
  }
  if (num[0] == '0' && n > 1) {
    cout << "-1" << endl;
  } else {
    cout << num << endl;
  }
  return 0;
}
