#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int> > SC(M);
  for (int i = 0; i < M; i++) {
    cin >> SC[i].first >> SC[i].second;
  }
  sort((SC).begin(), (SC).end());
  vector<int> ans(N, 0);
  if (M >= 2) {
    for (int i = 0; i < M - 1; i++) {
      if (SC[i].first == SC[i + 1].first && SC[i].second != SC[i + 1].second) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (N != 1) {
    if (SC[0].first == 1 && SC[0].second == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < M; i++) {
    ans[SC[i].first - 1] = SC[i].second;
  }
  if (N == 1) {
    cout << ans[0] << endl;
  } else {
    for (int i = 0; i < N; i++) {
      if (i == 0) {
        if (ans[i] == 0) {
          cout << 1;
        } else {
          cout << ans[i];
        }
      } else {
        cout << ans[i];
      }
    }
    cout << endl;
  }
}
