#include <bits/stdc++.h>
using namespace std;
void solve(long long N, long long M, std::vector<int> s, std::vector<int> c) {
  vector<int> ret(N, -1);
  for (int i = 0; i < M; i++) {
    if (ret[s[i] - 1] == -1 || ret[s[i] - 1] == c[i]) {
      ret[s[i] - 1] = c[i];
    } else {
      printf("-1\n");
      return;
    }
  }
  if (ret[0] == 0) {
    printf("-1\n");
    return;
  } else if (ret[0] > 0) {
    printf("%d", ret[0]);
  } else {
    printf("1");
  }
  for (int i = 1; i < N; i++) {
    if (ret[i] >= 0)
      printf("%d", ret[i]);
    else
      printf("0");
  }
  printf("\n");
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<int> s(M);
  std::vector<int> c(M);
  for (int i = 0; i < M; i++) {
    scanf("%d", &s[i]);
    scanf("%d", &c[i]);
  }
  solve(N, M, std::move(s), std::move(c));
  return 0;
}
