#include <bits/stdc++.h>
using namespace std;
long long mod(long long a, long long b) {
  if (a % b < 0) {
    return a % b + b;
  }
  return a % b;
}
long long mod_exp(long long a, long long b, long long c) {
  long long res = 1;
  a = a % c;
  while (b > 0) {
    if (b % 2 == 1) {
      res = (res * a) % c;
    }
    b /= 2;
    a = (a * a) % c;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
bool prime[3001];
void SieveOfEratosthenes() {
  memset(prime, true, sizeof(prime));
  prime[1] = false;
  for (int p = 2; p * p <= 3000; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= 3000; i += p) prime[i] = false;
    }
  }
}
long long powe[20];
void power() {
  powe[0] = 1;
  for (long long i = 1; i < 20; i++) {
    powe[i] = (powe[i - 1] * 10) % 998244353;
    if (powe[i] < 0) powe[i] += 998244353;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m, a, b;
  cin >> n >> m;
  long long numb[n];
  for (long long i = 0; i < n; i++) {
    numb[i] = -1;
  }
  for (long long i = 0; i < m; i++) {
    cin >> a >> b;
    if (numb[a - 1] == -1 || numb[a - 1] == b) {
      numb[a - 1] = b;
    } else {
      cout << "-1\n";
      exit(0);
    }
  }
  if (numb[0] == 0 && n > 1) {
    cout << "-1\n";
    exit(0);
  }
  for (long long i = 0; i < n; i++) {
    if (numb[i] == -1) {
      numb[i] = 8;
    }
    cout << numb[i];
  }
  return 0;
}
