#include <bits/stdc++.h>
using namespace std;
template <typename T>
T getSum(T array[], int length) {
  T sum = 0;
  for (int i = 0; i < length; i++) {
    sum += array[i];
  }
  return sum;
}
string ToString(int i) {
  char buffer[1000];
  sprintf(buffer, "%d", i);
  return string(buffer);
}
string convertToN(long n, int base) {
  string ans = "";
  while (n != 0) {
    int temp = n % base;
    ans = ToString(temp) + ans;
    n /= base;
  }
  return ans;
}
int main() {
  int N, M;
  scanf("%d %d", &N, &M);
  int s[M], c[M];
  for (int i = 0; i < M; i++) {
    scanf("%d %d", &s[i], &c[i]);
  }
  int max;
  if (N == 1) {
    max = 9;
    if (M == 0) {
      printf("%d\n", 1);
      return 0;
    }
  } else if (N == 2) {
    max = 99;
    if (M == 0) {
      printf("%d\n", 10);
      return 0;
    }
  } else {
    max = 999;
    if (M == 0) {
      printf("%d\n", 100);
      return 0;
    }
  }
  for (int i = 0; i <= max; i++) {
    string str = ToString(i);
    int size = str.size();
    if (size != N) {
      continue;
    }
    for (int j = 0; j < M; j++) {
      if (str[s[j] - 1] != ToString(c[j]).c_str()[0]) {
        break;
      }
      if (j == M - 1) {
        printf("%d\n", i);
        return 0;
      }
    }
  }
  printf("%d\n", -1);
  return 0;
}
