#include <bits/stdc++.h>
int const MOD = 1e9 + 7;
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> num(n, -1);
  while (m--) {
    int p, q;
    cin >> p >> q;
    if (p == 1) {
      if (num[0] == -1 || (num[0] != -1 && num[0] > q)) num[0] = q;
    } else if (p == 2) {
      if (num[1] == -1 || (num[1] != -1 && num[1] > q)) num[1] = q;
    } else {
      if (num[2] == -1 || (num[2] != -1 && num[2] > q)) num[2] = q;
    }
  }
  if (n > 1 && num[0] == -1)
    cout << "-1";
  else
    for (int &i : num) {
      if (i == -1) i = 0;
      cout << i;
    }
  cout << '\n';
}
