#include <bits/stdc++.h>
using namespace std;
int C[4];
int main() {
  for (int i = 0; i <= 3; i++) {
    C[i] = -1;
  }
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      cout << -1 << "\n";
      return 0;
    }
    if (C[s] != -1 && C[s] != c) {
      cout << -1 << "\n";
      return 0;
    } else {
      C[s] = c;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (C[i] == -1) {
      C[i] = (i != 1) ? 0 : 1;
    }
  }
  cout << C[1] * 10 * 10 + C[2] * 10 + C[3] << "\n";
}
