#include <bits/stdc++.h>
using namespace std;
vector<bool> prime(100 + 1, true);
void prime_table(void) {
  prime[0] = false;
  prime[1] = false;
  for (long long i = 2; i * i <= 100; i++) {
    if (!prime[i]) {
      continue;
    }
    for (long long j = i + i; j <= 100; j += j + i) {
      prime[j] = false;
    }
  }
}
bool IsPrime(long long num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  double sqrtNum = sqrt(num);
  for (long long i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i - 1);
      if (i * i != n) {
        ret.push_back((n / i) - 1);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
long long a, b;
void f(long long x) {
  a = x % 10;
  b = 0;
  while (x) {
    b = x;
    x /= 10;
  }
}
signed main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> ans(N);
  bool check = true;
  for (long long i = (0); i < (N); i++) {
    ans[i] = 10;
  }
  for (long long i = (0); i < (M); i++) {
    long long s, c;
    cin >> s >> c;
    if (ans[s - 1] != c && ans[s - 1] != 10) {
      check = false;
    } else {
      ans[s - 1] = c;
    }
  }
  if (ans[0] != 10 && ans[0] == 0) {
    check = false;
  }
  if (ans[0] == 10) {
    ans[0] = 1;
  }
  if (check)
    for (long long i = (0); i < (N); i++) {
      if (ans[i] == 10) {
        cout << 0;
      } else {
        cout << ans[i];
      }
    }
  else
    cout << "-1";
  cout << endl;
}
