#include <bits/stdc++.h>
using namespace std;
long long digits(long long n) {
  long long d = 0;
  if (n == 0) return 1;
  while (n > 0) {
    n /= 10;
    d++;
  }
  return d;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<char> d[3];
  for (int i = 0; i < m; i++) {
    int s;
    char c;
    cin >> s >> c;
    s--;
    d[s].push_back(c);
  }
  for (int i = 0; i < 3; i++) {
    if (d[i].size() >= 2) {
      cout << -1 << endl;
      return 0;
    }
  }
  int minv = 1000;
  for (int i = 0; i < 1000; i++) {
    if (digits(i) != n) continue;
    string t = to_string(i);
    bool flag = 1;
    for (int i = 0; i < n; i++) {
      if (d[i].size() == 0) continue;
      if (find(d[i].begin(), d[i].end(), t[i]) == d[i].end()) flag = 0;
    }
    if (flag) minv = min(minv, stoi(t));
  }
  if (minv == 1000)
    cout << -1 << endl;
  else
    cout << minv << endl;
  return 0;
}
