#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> sc;
  for (int i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    sc.emplace_back(s, c);
  }
  sort(sc.begin(), sc.end());
  for (int i = 1; i < M; ++i) {
    if (sc[i - 1].first == sc[i].first && sc[i - 1].second != sc[i].second) {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<int> a(N + 1);
  for (int i = 0; i < M; ++i) {
    a[sc[i].first] = sc[i].second;
  }
  int zero = 0;
  for (int i = 1; i <= N && a[i] == 0; ++i) {
    zero += 1;
  }
  if (N > 1 && zero > 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= N; ++i) {
    cout << a[i];
  }
  cout << endl;
  return 0;
}
