#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1e9;
const long long mod = 1000000007;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long pow_kai(long long a, long long n) {
  long long x = 1;
  while (n > 0) {
    if (n & 1) {
      x = x * a;
    }
    a = a * a;
    n >>= 1;
  }
  return x;
}
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  vector<int> S(m);
  vector<char> C(m);
  int s;
  char c;
  for (int i = 0; i < (m); i++) {
    cin >> S[i] >> C[i];
  }
  if (n > 1 && m == 0) {
    cout << -1 << "\n";
    return 0;
  }
  for (int i = 0; i <= 999; ++i) {
    string ss = to_string(i);
    int cnt = 0;
    for (int j = 0; j < (m); j++) {
      if (ss[S[j] - 1] == C[j]) {
        cnt++;
      }
    }
    if (ss.size() == n && cnt == m) {
      cout << ss << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
}
