#include <bits/stdc++.h>
int main() {
  int n, m;
  int s[5];
  int c[5];
  scanf("%d %d", &n, &m);
  for (int a = 0; a < m; a++) {
    scanf("%d %d", &s[a], &c[a]);
  }
  int ans, max;
  if (n == 1) ans = 0, max = 10;
  if (n == 2) ans = 10, max = 100;
  if (n == 3) ans = 100, max = 1000;
  for (int x = ans; x < max; x++) {
    std::string str;
    str = std::to_string(x);
    for (int a = 0; a < m; a++) {
      std::string strs;
      strs = std::to_string(c[a]);
      if (str[s[a] - 1] != strs[0]) {
        break;
      }
      if (a == m - 1) {
        printf("%d", x);
        return 0;
      }
    }
  }
  printf("-1");
  return 0;
}
