#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int num[n];
  memset(num, 0, sizeof(num));
  while (m--) {
    int u, v;
    cin >> u >> v;
    u--;
    if (!num[u] || num[u] > v) num[u] = v;
  }
  if (num[0] == 0) {
    printf("-1\n");
  } else {
    for (int i = 0; i < n; i++) {
      printf("%d", num[i]);
    }
    printf("\n");
  }
  return 0;
}
