#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
int main() {
  int N, M;
  cin >> N >> M;
  bool falg = true;
  vector<pair<int, char> > data(M);
  for (int i = 0; i < M; i++) {
    cin >> data[i].first >> data[i].second;
  }
  sort(data.begin(), data.end(), greater<pair<int, int> >());
  for (int i = 0; i < N - 1; i++) {
    if (data[i].first == data[i + 1].first &&
        data[i].second != data[i + 1].second) {
      cout << "-1" << endl;
      return (0);
    }
  }
  int digit = data[0].first;
  vector<char> s(digit, '0');
  for (int i = 0; i < N; i++) {
    s[data[i].first - 1] = data[i].second;
  }
  if (s[0] == '0') {
    cout << "-1" << endl;
    return (0);
  }
  for (int i = 0; i < s.size(); i++) {
    cout << s[i];
  }
  cout << endl;
}
