#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  vector<vector<int>> num(n, vector<int>{});
  for (int i = 0; i < m; i++) {
    if (num[s[i] - 1].size() == 0) {
      num[s[i] - 1].push_back(c[i]);
      continue;
    }
    for (int a : num[s[i] - 1]) {
      if (a != c[i]) {
        num[s[i] - 1].push_back(c[i]);
        break;
      }
    }
  }
  if (num[0].size() != 1) {
    cout << -1 << endl;
    return 0;
  } else if (num[0][0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (num[i].size() > 1) {
      cout << -1 << endl;
      return 0;
    }
    if (num[i].size() == 0) num[i].push_back(0);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += num[i][0] * pow(10, n - 1 - i);
    cout << num[i][0] * pow(10, n - 1 - i) << " " << ans << endl;
  }
  cout << ans << endl;
  return 0;
}
