#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
const long long INF = numeric_limits<long long>::max();
int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> digits(N, -1);
  bool isOk = true;
  for (ll i = 0; i < (M); i++) {
    ll s, c;
    cin >> s >> c;
    if (digits[s - 1] != -1 && digits[s - 1] != c) {
      isOk = false;
      break;
    }
    digits[s - 1] = c;
  }
  if (digits[0] == 0) {
    isOk = false;
  }
  if (!isOk) {
    cout << (-1) << "\n";
  } else {
    ll ans = 0;
    for (ll i = 0; i < (N); i++) {
      ans *= 10;
      if (digits[i] == -1) {
        if (i == 0 && N != 1) {
          ans += 1;
        } else {
          ans += 0;
        }
      } else {
        ans += digits[i];
      }
    }
    cout << (ans) << "\n";
  }
  return 0;
}
