#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, char>;
signed main() {
  int n, m;
  cin >> n >> m;
  vector<P> v(m);
  for (int i = 0; i < (m); ++i) {
    int first;
    char second;
    cin >> first >> second;
    --first;
    v[i] = P(first, second);
  }
  int ans = pow(10, n - 1);
  if (n == 1) ans = 0;
  sort((v).begin(), (v).end());
  string s = to_string(ans);
  int prev = -1;
  char prev_char = 'a';
  for (int i = 0; i < (v.size()); ++i) {
    P tmp = v[i];
    if (tmp.first == 0 && tmp.second == '0') {
      cout << -1 << endl;
      return 0;
    }
    if (prev == tmp.first && prev_char != tmp.second) {
      cout << -1 << endl;
      return 0;
    }
    s[tmp.first] = tmp.second;
    prev = tmp.first;
    prev_char = tmp.second;
  }
  cout << s;
  cout << "\n";
  return 0;
}
