#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<set<int>> vec(11);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    vec[a].insert(b);
  }
  for (int i = 1; i <= M; ++i) {
    if (vec[i].size() > 1) {
      cout << "-1\n";
      return 0;
    }
  }
  int num = 0;
  for (int i = 1; i <= M; ++i) {
    if (vec[i].size() != 0) num += *vec[i].begin();
    num *= 10;
  }
  if (num == 0 && N != 1) {
    cout << "-1\n";
    return 0;
  }
  if (N == 1 && M == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (M == 0) {
    cout << pow(10, N - 1) << endl;
    return 0;
  }
  cout << num / 10 << "\n";
}
