#include <bits/stdc++.h>
using namespace std;
int a[4];
signed main() {
  for (register int i = 1; i <= 4; ++i) a[i] = -1;
  int n, m;
  scanf("%d%d", &n, &m);
  if (m == 0) {
    if (n == 1) return puts("0"), 0;
    printf("1");
    for (register int i = 1; i < n; ++i) printf("0");
    return puts(""), 0;
  }
  for (register int i = 1; i <= m; ++i) {
    int s, c;
    scanf("%d%d", &s, &c);
    if (a[s] == -1)
      a[s] = c;
    else if (a[s] != c)
      return puts("-1"), 0;
  }
  int L;
  for (register int i = 1; i <= 4; ++i)
    if (a[i] != -1) {
      L = i;
      break;
    }
  for (register int i = L; i < L + n; ++i)
    if (a[i] == -1)
      printf("0");
    else
      printf("%d", a[i]);
  system("pause");
  return puts(""), 0;
}
