#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> d(N, -1);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (d[s] != -1 && d[s] != c || d[0] == 0 && N > 1) {
      cout << -1;
      return 0;
    }
    d[s] = c;
  }
  if (d[0] == -1) {
    if (N > 1) {
      d[0] = 1;
    } else {
      d[0] = 0;
    }
  }
  for (int i = 1; i < N; i++) {
    if (d[i] == -1) {
      d[i] = 0;
    }
  }
  if (N == 1) {
    cout << d[0];
  } else if (N == 2) {
    cout << d[0] * 10 + d[1];
  } else {
    cout << d[0] * 100 + d[1] * 10 + d[2];
  }
}
