#include <bits/stdc++.h>
using namespace std;
long long ex_gcd(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long ans = ex_gcd(b, a % b, x, y);
  long long tmp = x;
  x = y;
  y = tmp - a / b * y;
  return ans;
}
int a[10];
int main() {
  int n, m;
  int id, x;
  scanf("%d%d", &n, &m);
  map<int, int> mp;
  bool flag = true;
  while (m--) {
    scanf("%d%d", &id, &x);
    if (mp[id]) {
      if (mp[id] != x + '0') {
        flag = false;
        continue;
      }
    } else {
      mp[id] = x + '0';
      a[id] = x + '0';
    }
  }
  if (a[1] == '0')
    printf("-1\n");
  else if (!flag)
    printf("-1\n");
  else {
    if (a[1])
      printf("%c", a[1]);
    else
      printf("1");
    for (int i = 2; i <= n; i++) {
      if (a[i])
        printf("%c", a[i]);
      else
        printf("0");
    }
    printf("\n");
  }
}
