#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans = 0;
  bool check = true;
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> pair;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    pair.push_back(make_pair(a, b));
  }
  sort(pair.begin(), pair.end());
  for (int i = 0; i < M - 1; i++) {
    if (pair[i].first == pair[i + 1].first &&
        pair[i].second != pair[i + 1].second) {
      check = false;
    }
  }
  if (pair[0].first == 1 && pair[0].second == 0) {
    check = false;
  }
  for (int i = 0; i < M - 1; i++) {
    if (pair[i].first != pair[i + 1].first) {
      ans += pow((double)10, N - (double)pair[i].first) * pair[i].second;
    }
  }
  ans += pow((double)10, N - (double)pair[M - 1].first) * pair[M - 1].second;
  if (check) {
    cout << (int)ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
