#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> data(2, vector<int>(M));
  vector<int> ans(N);
  bool X = true;
  int countA = 0;
  int countB = 0;
  int countC = 0;
  for (int i = 0; i < M; i++) 
    cin >> data.at(0).at(i) >> data.at(1).at(i);
  for (int i = 0; i < M; i++) {
    if (data.at(0).at(i) == 1 && N >= 1) {
      if (countA != 0 && ans.at(0) != data.at(1).at(i)) {
        X = false;
        break;
      }
      else {
        ans.at(0) = data.at(1).at(i);
        countA++;
      }
    }
    if (data.at(0).at(i) == 2 && N >= 2) {
      if (countB != 0 && ans.at(1) != data.at(1).at(i)) {
        X = false;
        break;
      }
      else {
        ans.at(1) = data.at(1).at(i);
        countB++;
      }
    }
    if (data.at(0).at(i) == 2 && N < 2) {
      X = false;
      break;
    }
    if (data.at(0).at(i) == 3 && N >= 3) {
      if (countC != 0 && ans.at(2) != data.at(1).at(i)) {
        X = false;
        break;
      }
      else {
        ans.at(2) = data.at(1).at(i);
        countC++;
      }
    }
    if (data.at(0).at(i) == 3 && N < 3) {
      X = false;
      break;
    }
    if (X == 0)
      cout << -1 << endl;
    else if (X == 1)
      cout << ans.at(0) + ans.at(1)*10 + ans.at(2)*100 << endl;
}
