#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M, 0), c(M, 0), num(M, 10);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  if (N > M) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < M; i++) {
    num[s[i] - 1] = num[s[i] - 1] > c[i] ? c[i] : num[s[i] - 1];
  }
  for (int i = 0; i < M; i++) {
    if (num[i] == 10)
      cout << 0;
    else
      cout << num[i];
  }
  return 0;
}
