#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> beki10(4);
  beki10[0] = 1;
  for (int i = 1; i < 4; i++) beki10[i] = beki10[i - 1] * 10;
  int N, M;
  cin >> N >> M;
  vector<int> jouken(N + 1, -1);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if ((jouken[s] != -1 && jouken[s] != c) || (s == 1 && c == 0)) {
      cout << -1 << endl;
      return 0;
    } else {
      jouken[s] = c;
    }
  }
  for (int i = beki10[N - 1]; i < beki10[N]; i++) {
    bool flag = true;
    for (int j = 0; j < N; j++) {
      if (jouken[j + 1] != -1) {
        if ((i / beki10[N - j - 1]) % 10 != jouken[j + 1]) flag = false;
      }
    }
    if (flag) {
      cout << i << endl;
      break;
    }
  }
}
