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