#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<pair<int, char>> p;
  for (int i = 0; i < m; i++) {
    int si;
    char ci;
    cin >> si >> ci;
    p.push_back(make_pair(si, ci));
  }
  char number[n];
  for (int i = 0; i < n; i++) number[i] = '#';
  for (int i = 0; i < m; i++) {
    if (number[p[i].first - 1] != '#' &&
        number[p[i].first - 1] != p[i].second) {
      cout << "-1\n";
      return 0;
    } else
      number[p[i].first - 1] = p[i].second;
  }
  for (int i = 0; i < n; i++)
    if (number[i] == '#') number[i] = '0';
  for (int i = 1; i < n; i++) {
    if (number[i - 1] == '0') {
      cout << "-1\n";
      return 0;
    } else
      break;
  }
  for (int i = 0; i < n; i++) cout << number[i];
  cout << "\n";
  return 0;
}
