#include <bits/stdc++.h>
using namespace std;
int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) {
    return 1;
  } else {
    return 0;
  }
}
int main() {
  int N;
  cin >> N;
  int M;
  cin >> M;
  vector<vector<int>> vec(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    cin >> vec.at(i).at(0) >> vec.at(i).at(1);
  }
  vector<int> a(M);
  vector<int> b(M);
  for (int i = 0; i < M; i++) {
    a.at(i) = vec.at(i).at(0);
    b.at(i) = vec.at(i).at(1);
  }
  int p = 0;
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < i; j++) {
      if (a.at(j) == a.at(i)) {
        if (b.at(j) != b.at(i)) {
          p++;
        }
      }
    }
    for (int k = i + 1; k < M; k++) {
      if (a.at(k) == a.at(i)) {
        if (b.at(k) != b.at(i)) {
          p++;
        }
      }
    }
  }
  int q = 0;
  for (int i = 0; i < M; i++) {
    if ((a.at(i) == 1) && (b.at(i) == 0)) {
      q++;
    }
  }
  if ((p > 0) || (q > 0)) {
    cout << -1 << endl;
  } else {
    int res = 0;
    vector<int> t(0);
    for (int i = 0; i < M; i++) {
      if (vector_finder(t, a.at(i)) == 0) {
        res += b.at(i) * std::pow(10, N - a.at(i));
        t.push_back(a.at(i));
      }
    }
    if ((N = 1) && (res == 0)) {
      res = 0;
    } else if (res < std::pow(10, N - 1)) {
      res += std::pow(10, N - 1);
    }
    cout << res << endl;
  }
}
