#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  int ans[N];
  bool can[N];
  for (int i = 0; i < N; i++) {
    ans[i] = 0;
    can[i] = true;
  }
  while (M--) {
    int s, c;
    cin >> s >> c;
    --s;
    if (can[s]) {
      ans[s] = c;
      can[s] = false;
    } else {
      if (ans[s] == c) {
        continue;
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (N != 1 && ans[0] == 0) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < N; i++) {
      cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}
