#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M;
  cin >> N >> M;
  if (N < 1 || N > 3) {
    printf("-1");
    return 1;
  }
  if (M < 0 || M > 5) {
    printf("-1");
    return 1;
  }
  long long s[M], c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    if (s[i] < 1 || s[i] > N) {
      printf("-1");
      return 1;
    }
    if (c[i] < 0 || c[i] > 9) {
      printf("-1");
      return 1;
    }
  }
  long long ans[N];
  for (int i = 0; i < N; i++) {
    ans[i] = -1;
  }
  for (int i = 0; i < M; i++) {
    if (ans[s[i] - 1] != -1) {
      if (ans[s[i] - 1] != c[i]) {
        printf("-1");
        return 1;
      }
    } else {
      ans[s[i] - 1] = c[i];
    }
  }
  if (N > 1 && ans[0] == 0) {
    printf("-1");
    return 1;
  }
  for (int i = 0; i < N; i++) {
    if (ans[i] == -1) {
      if (N > 1 && i == 0) {
        ans[i] = 1;
      } else {
        ans[i] = 0;
      }
    }
    printf("%d", ans[i]);
  }
  return 0;
}
