#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<string> s(M), c(M);
  for (int i = 0; i < M; ++i) cin >> s[i] >> c[i];
  bool result = false;
  vector<string> st(N);
  for (int i = 0; i < N; ++i) st[i] = "0";
  vector<bool> r(N);
  for (int i = 0; i < N; ++i) r[i] = false;
  for (int i = 0; i < M; ++i) {
    if (r[stoi(s[i]) - 1] == false) {
      st[stoi(s[i]) - 1] = c[i];
      r[stoi(s[i]) - 1] = true;
    } else if (r[stoi(s[i]) - 1] == true) {
      if (st[stoi(s[i]) - 1] == c[i]) {
      } else {
        result = true;
        break;
      }
    }
  }
  if ((st[0] == "0" && N != 1)) {
    cout << -1 << endl;
  } else if (result == true) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < N; ++i) {
      cout << st[i];
    }
  }
}
