#include <bits/stdc++.h>
using namespace std;
const int Maxn = 4;
int N, M;
int s[Maxn];
int c[Maxn];
int main() {
  cin >> N >> M;
  bool failed = false;
  for (int i = 1; i <= M && !failed; i++) {
    int a, b;
    cin >> a >> b;
    if (c[a] == 0) {
      if (a == 1) {
        if (b == 0) {
          failed = true;
        } else {
          c[a] = 1;
          s[a] = b;
        }
      } else {
        c[a] = 1;
        s[a] = b;
      }
    } else {
      if (s[a] != b)
        failed = true;
      else
        continue;
    }
  }
  if (failed)
    printf("-1");
  else {
    for (int i = 1; i <= N; i++) {
      if (i == 1) {
        if (c[1] == 0)
          printf("1");
        else
          printf("%d", s[1]);
      } else {
        if (!c[i])
          printf("0");
        else
          printf("%d", s[i]);
      }
    }
  }
  return 0;
}
