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