#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int solve() { return 0; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  map<int, int> ma, na;
  int a, b;
  while (m--) {
    cin >> a >> b;
    if ((ma[a] > 0 && ma[a] != b) || (a == 1 && b == 0)) {
      cout << -1;
      return 0;
    }
    ma[a] = b;
  }
  if (ma.size() > n) {
    cout << "-1";
    return 0;
  }
  (ma[1] == 0) ? ma[1] = 1 : ma[1] += 0;
  for (int i = (int)(1); i < (int)(n + 1); ++i) {
    (ma[i] > 0) ? cout << ma[i] : cout << 0;
  }
  return 0;
}
