#include <bits/stdc++.h>
using namespace std;
std::vector<unsigned long long> genprimevec(const unsigned long long N);
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<pair<int, int>> pv(m);
  int s, c;
  for (unsigned long long i = 0; i < (unsigned long long)(n); ++i) {
    a[i] = -1;
  }
  for (unsigned long long i = 0; i < (unsigned long long)(m); ++i) {
    cin >> s >> c;
    pv[i].first = s - 1;
    pv[i].second = c;
  }
  for (unsigned long long i = 0; i < (unsigned long long)(m); ++i) {
    if (a[pv[i].first] != -1 && (a[pv[i].first] != pv[i].second)) {
      std::cout << -1 << endl;
      return 0;
    }
    if (pv[i].first == 0 && pv[i].second == 0) {
      if (n == 1) {
        cout << 0 << endl;
        return 0;
      }
      std::cout << -1 << endl;
      return 0;
    }
    a[pv[i].first] = pv[i].second;
  }
  std::string ans;
  for (unsigned long long i = 0; i < (unsigned long long)(n); ++i) {
    if (a[i] == -1) {
      if (i == 0) {
        a[i] = 0;
      } else {
        a[i] = 0;
      }
    }
    ans.push_back(a[i] + '0');
  }
  cout << stoi(ans) << endl;
  return 0;
}
long long extgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  long long d = extgcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
std::vector<unsigned long long> genprimevec(const unsigned long long N) {
  std::vector<bool> is_prime(N + 1);
  for (unsigned long long i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  std::vector<unsigned long long> P;
  for (unsigned long long i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (unsigned long long j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}
