#include <bits/stdc++.h>
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
int dig(int n) {
  if (n == 0) return 1;
  int res = 0;
  while (n > 0) {
    res++;
    n /= 10;
  }
  return res;
}
int d(int i, int j) {
  if (i == 0) {
    return 0;
  } else if (i == 1) {
    return 100 * j;
  } else if (i == 2) {
    return 10 * j;
  } else {
    return j;
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, char>> data(m, pair<int, char>(m, 0));
  for (int i = 0; i < (m); ++i) {
    cin >> data.at(i).first >> data.at(i).second;
  }
  sort(data.begin(), data.end());
  bool hoge = true;
  for (int i = 0; i < (m - 1); ++i) {
    if (data.at(i).first == data.at(i + 1).first) {
      if (data.at(i).second != data.at(i + 1).second) {
        hoge = false;
      } else {
        data.at(i).first = 0;
      }
    }
  }
  char c[3] = {'0', '0', '0'};
  bool cn[3] = {true, true, true};
  if (hoge) {
    for (int i = 0; i < (m); ++i) {
      if (data.at(i).first != 0) {
        c[data.at(i).first - 1] = data.at(i).second;
        cn[data.at(i).first - 1] = false;
      }
    }
    if (n == 3 && c[0] != '0') {
      cout << c[0] << c[1] << c[2] << endl;
      return 0;
    } else if (cn[0]) {
      cout << '1' << c[1] << c[2] << endl;
      return 0;
    }
    if (n == 2 && c[1] != '0') {
      cout << c[1] << c[2] << endl;
      return 0;
    } else if (cn[2]) {
      cout << '1' << c[2] << endl;
      return 0;
    }
    if (n == 1 && c[2] != '0') {
      cout << c[2] << endl;
      return 0;
    } else {
      cout << -1 << endl;
      return 0;
    }
  } else {
    cout << -1 << endl;
  }
  return 0;
}
