#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M, count = 0, ans = 0;
  cin >> N >> M;
  if (M != 0) {
    vector<int> A(N);
    vector<pair<int, int> > t(M);
    for (int i = 0; i < (int)(M); i++) cin >> t.at(i).first >> t.at(i).second;
    sort(t.begin(), t.end());
    if (t.at(0).first == 1 && t.at(0).second == 0) count = -1;
    for (int i = 0; i < (int)(N); i++) {
      A.at(i) = 0;
    }
    for (int i = 0; i < (int)(M); i++) {
      A.at(t.at(i).first - 1) = t.at(i).second;
    }
    for (int i = 0; i < (int)(M - 1); i++) {
      if (t.at(i).first == t.at(i + 1).first &&
          t.at(i).second != t.at(i + 1).second)
        count = -1;
    }
    if (A.at(0) == 0) A.at(0) = 1;
    for (int i = 0; i < (int)(N); i++) {
      ans += A.at(i) * pow(10, N - 1 - i);
    }
    if (count < 0)
      cout << -1 << endl;
    else
      cout << ans << endl;
  } else if (M == 0) {
    int ans = pow(10, N - 1);
    cout << ans << endl;
  }
}
