#include <bits/stdc++.h>
int main(void) {
  int n;
  int m;
  scanf("%d %d", &n, &m);
  int s[m];
  int c[m];
  int result[n];
  for (int j = 0; j < n; j++) {
    result[j] = 0;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &s[i], &c[i]);
  }
  int tmp_s[m];
  int tmp_c[m];
  for (int i = 0; i < m; i++) {
    tmp_s[i] = s[i];
    tmp_c[i] = c[i];
  }
  for (int i = 0; i < m; i++) {
    result[s[i] - 1] = c[i];
    for (int j = 0; j < m; j++) {
      if (tmp_s[i] == s[j] && tmp_c[i] > c[j]) {
        result[s[i] - 1] = c[j];
      }
    }
  }
  if (result[0] == 0) {
    printf("-1");
    return 0;
  }
  for (int j = 0; j < n; j++) {
    printf("%d", result[j]);
  }
  return 0;
}
