#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, char>> a(M);
  for (int i = 0; i < M; ++i) {
    int s;
    char c;
    cin >> s >> c;
    --s;
    a[i] = make_pair(s, c);
  }
  bool ok = true;
  for (int i = 0; i < M - 1; ++i)
    ok = ok && (a[i].first != a[i + 1].first || a[i].second == a[i + 1].second);
  if (!ok) {
    cout << "-1" << endl;
  } else {
    string ans = string(N, '0');
    if (N > 1) {
      ans[0] = '1';
    }
    for (const auto &x : a) {
      ans[x.first] = x.second;
    }
    cout << ans << endl;
  }
}
