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