#include <bits/stdc++.h>
using namespace std;
char ch, B[1 << 20], *S = B, *T = B;
int aa, bb;
int rd() {
  while (ch = (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T)
                   ? 0
                   : *S++),
         !(ch >= '0' && ch <= '9') && ch != '-')
    ;
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while (ch = (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T)
                   ? 0
                   : *S++),
         (ch >= '0' && ch <= '9'))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
int n, m, s[4], c[6];
inline void work() {
  n = rd();
  m = rd();
  if (m == 0) {
    printf("0\n");
    return;
  }
  for (register int i = 1; i <= m; ++i) {
    s[i] = rd();
    c[i] = rd();
  }
  for (register int i = 0; i <= 1000; ++i) {
    string ss = to_string(i);
    if ((int)ss.size() != n) continue;
    bool ok = 1;
    for (register int i = 1; i <= m; ++i)
      if (ss[s[i] - 1] != c[i] + '0') {
        ok = 0;
        break;
      }
    if (ok) {
      printf("%d\n", i);
      return;
    }
  }
  printf("-1\n");
}
int main() {
  work();
  return 0;
}
