#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> data(n, -1);
  for (int i = 0; i < m; i++) {
    int c, s;
    cin >> s >> c;
    s--;
    if (data[s] != -1 && data[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    if (n != 1 && s == 0 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    data[s] = c;
  }
  int ans = 0, ten = 1;
  for (int i = n - 1; i >= 0; i--) {
    cout << data[i] << endl;
    if (data[i] == -1) {
      ten *= 10;
      continue;
    }
    ans += data[i] * ten;
    ten *= 10;
  }
  cout << ans << endl;
}
