#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P(N, -1);
  for (ll i = 0; i < (M); i++) {
    int S, C;
    cin >> S >> C;
    S -= 1;
    if (P[S] == -1) {
      P[S] = C;
    } else if (P[S] == C) {
      P[S] = C;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  int zeroflag = 0;
  for (ll i = 0; i < (N); i++) {
    if (P[i] == 0 && zeroflag == 0) {
      cout << -1 << endl;
      return 0;
    } else if (P[i] == -1 && zeroflag == 0) {
      P[i] = 1;
      zeroflag = 1;
    } else if (P[i] == -1) {
      P[i] = 0;
    } else {
      zeroflag = 1;
    }
  }
  int ans = 0;
  for (ll i = 0; i < (N); i++) {
    ans *= 10;
    ans += P[i];
  }
  cout << ans << endl;
}
