#include <bits/stdc++.h>
using namespace std;
const long long INF = 9223372036854775807;
const long long half_inf = 0x3f3f3f3f;
const long long inf = 0x7fffffff;
const long long mod = 1e9 + 7;
const long long maxn = 200005;
int a[100] = {0};
int main() {
  int T, n, m, s, c, flag = 1, t = 0;
  scanf("%d%d", &n, &m);
  a[1] = 1;
  while (m--) {
    scanf("%d%d", &s, &c);
    if (s != 1) {
      if (a[s] != 0 && a[s] != c)
        flag = 0;
      else
        a[s] = c;
    } else {
      if (c == 0) flag = 0;
      if (t && a[1] != c)
        flag = 0;
      else {
        a[1] = c;
        t = 1;
      }
    }
  }
  if (n == 2 && a[1] == 0) {
    flag = 0;
  }
  if (n == 3 && a[1] == 0) {
    flag = 0;
  }
  if (flag) {
    for (int i = 1; i <= n; i++) printf("%d", a[i]);
  } else
    printf("-1");
  return 0;
}
