#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;
int f(int n) {
  int ans = 1;
  for (int i = 0; i < n; i++) {
    ans *= 10;
  }
  return ans;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<vi> data(M, vi(2));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> data.at(i).at(j);
    }
  }
  sort(data.begin(), data.end());
  vi ans(N);
  int num = 0;
  if (M == 1) {
    ans.at(data.at(0).at(0) - 1) = data.at(0).at(1);
  }
  for (int i = 0; i < M - 1; i++) {
    if (data.at(i).at(0) == data.at(i + 1).at(0) &&
        data.at(i).at(1) != data.at(i + 1).at(1)) {
      cout << -1 << endl;
      return 0;
    }
    ans.at(data.at(i).at(0) - 1) = data.at(i).at(1);
    if (i = M - 2) {
      ans.at(data.at(M - 1).at(0) - 1) = data.at(M - 1).at(1);
    }
  }
  for (int i = 0; i < N; i++) {
    num += ans.at(i) * f(N - i - 1);
  }
  if (N != 1 && num == 0) {
    cout << -1 << endl;
  } else {
    cout << num << endl;
  }
}
