#include <bits/stdc++.h>
using namespace std;
constexpr int Inf = 1000000001;
constexpr long long INF = 9 * 1e18;
constexpr long long MOD = 1000000007;
const double PI = 3.1415926535897;
int main() {
  int N, M;
  cin >> N >> M;
  bool ret = true;
  vector<int> vec(N, -1);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    A--;
    if (vec.at(A) == -1) {
      vec.at(A) = B;
    } else if (vec.at(A) != B) {
      ret = false;
    }
  }
  if (ret == false || (N != 1 && vec.at(0) == 0)) {
    cout << -1 << endl;
    return 0;
  }
  if (N == 1 && vec.at(0) == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    if (i == 0 && vec.at(i) == -1) {
      cout << 1;
    } else if (vec.at(i) == -1) {
      cout << 0;
    } else {
      cout << vec.at(i);
    }
  }
  cout << endl;
}
