#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s, c;
  vector<pair<int, int>> A(M);
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    A[i].first = s;
    A[i].second = c;
  }
  int higher = pow(10, N) - 1;
  int lower = pow(10, N - 1);
  int num = -1;
  bool find_num = false;
  for (int i = lower; i <= higher; i++) {
    num = i;
    vector<int> B(N + 1);
    for (int k = N; k >= 1; k--) {
      B[k] = num % 10;
      num /= 10;
    }
    bool flag = true;
    for (int j = 0; j < M; j++) {
      s = A[j].first;
      c = A[j].second;
      flag *= B[s] == c;
    }
    if (flag) {
      find_num = true;
      num = i;
      break;
    }
  }
  if (find_num) {
    cout << num << endl;
  } else {
    cout << -1 << endl;
  }
}
