#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M);
  vector<int> C(M);
  for (int i = 0; i < M; i++) {
    cin >> S[i] >> C[i];
  }
  for (int j = 0; j < M; j++) {
    for (int k = 0; k < M; k++) {
      if (S[j] == S[k]) {
        if (C[j] != C[k]) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
  }
  vector<int> ans(N, 0);
  for (int l = 0; l < M; l++) {
    ans[S[l] - 1] = C[l];
  }
  if (ans[0] == 0) {
    ans[0] = 1;
  }
  for (int m = 0; m < N; m++) {
    cout << ans[m];
  }
  cout << endl;
}
