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