#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  bool b = true;
  vector<int> a(N, -1);
  for (int i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) b = false;
    if (a[s - 1] == -1) {
      a[s - 1] = c;
    } else {
      if (a[s - 1] != c) b = false;
    }
  }
  if (b) {
    int sum = 0;
    for (int i = 0; i < N; ++i) {
      if (i == N - 1 && a[i] == -1)
        sum += 1 * pow(10, N - (i + 1));
      else if (a[i] == -1)
        sum += 0;
      else
        sum += a[i] * pow(10, N - (i + 1));
    }
    cout << sum;
  } else {
    cout << -1 << endl;
  }
}
