#include <bits/stdc++.h>
using namespace std;
int N, M;
typedef struct _Node {
  vector<struct _Node*> next;
} Node;
int main() {
  scanf("%d%d", &N, &M);
  int a, b, ans = 0;
  vector<int> data(N, -1);
  for (int i = 0; i < M; i++) {
    scanf("%d%d", &a, &b);
    if (data[a - 1] != -1 && data[a - 1] != b || N >= 2 && a == 1 && b == 0) {
      printf("-1");
      return 0;
    }
    data[a - 1] = b;
  }
  for (int i = 0; i < N; i++) ans *= 10, ans += data[i] == -1 ? 0 : data[i];
  printf("%d", ans);
  return 0;
}
