#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int> > v(M);
  int res = 0;
  bool ok = true;
  vector<int> b(N, -1);
  for (int i = 0; i < M; i++) {
    cin >> v[i].first >> v[i].second;
    v[i].first--;
    if (b[v[i].first] != -1 && b[v[i].first] != v[i].second) {
      ok = false;
    }
    if (i != 1 && v[i].second == 0) ok = false;
    b[v[i].first] = v[i].second;
  }
  for (int i = 0; i < N; i++) {
    if (b[i] != -1) {
      res += b[i] * pow(10, N - i - 1);
    }
  }
  if (res < pow(10, N - 1)) res += pow(10, N - 1);
  if (ok == true) {
    cout << res << endl;
  } else
    cout << -1 << endl;
}
