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