#include <bits/stdc++.h>
using namespace std;
long long int powmod(long long int a, long long int b) {
  long long int res = 1;
  a %= 1005;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 1005;
    a = a * a % 1005;
  }
  return res;
}
int nxt() {
  int x;
  scanf("%d", &x);
  return x;
}
int main() {
  int n = nxt(), m = nxt();
  vector<int> digit(n, -1);
  for (int i = 0; i < m; i++) {
    int s = nxt(), c = nxt();
    s--;
    if (digit[s] != -1 && digit[s] != c) {
      printf("-1");
      return 0;
    } else
      digit[s] = c;
  }
  if (digit[0] == 0 && n != 1) {
    printf("-1");
    return 0;
  }
  for (int i = 0; i < n; i++)
    if (digit[i] == -1) digit[i] = 0;
  digit[0] = 0;
  for (int i = 0; i < n; i++) printf("%d", digit[i]);
  return 0;
}
