#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    if (n == 3)
      cout << 100 << endl;
    else if (n == 2)
      cout << 10 << endl;
    else
      cout << 0 << endl;
    return 0;
  }
  vector<pair<int, int> > v(m);
  for (int i = 0; i < (m); i++) {
    int a, b;
    cin >> a >> b;
    --a;
    v[i].first = a;
    v[i].second = b;
  }
  vector<int> ans(n);
  sort(v.begin(), v.end());
  for (int i = 0; i < (m); i++)
    cout << v[i].first << ", " << v[i].second << endl;
  if (v[0].first == 0 && v[0].second == 0 && n != 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (m - 1); i++) {
    if (v[i].first == v[i + 1].first && v[i].second != v[i + 1].second) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < (m); i++) {
    if (v[i].first >= n) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < (m); i++) {
    ans[v[i].first] = v[i].second;
  }
  for (int i = 0; i < (n); i++) cout << ans[i] << endl;
  if (n >= 2) ans[0] = max(1, ans[0]);
  int answer = 0;
  for (int i = 0; i < (n); i++) {
    answer += ans[i] * pow(10, (n - i - 1));
  }
  cout << answer << endl;
  return 0;
}
