#include <bits/stdc++.h>
using namespace std;
uint16_t N;
uint16_t M;
vector<pair<int, int>> sc;
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    sc.push_back(make_pair(a, b));
  }
  if (M == 0) {
    cout << 0 << endl;
    return 0;
  }
  std::sort(sc.begin(), sc.end(),
            [](const pair<int, int>& a, const pair<int, int>& b) {
              return a.first < b.first;
            });
  auto itr = sc.begin();
  while (itr != sc.end() - 1) {
    if (itr->first == (itr + 1)->first) {
      if (itr->second != (itr + 1)->second) {
        cout << -1 << endl;
        return 0;
      } else {
        itr = sc.erase(itr);
      }
    } else {
      itr++;
    }
  }
  for (int i = 0; i < sc.size(); i++) {
    if (sc[i].second == 0) {
      if (sc[i].first != N) {
        if (N != 3) {
          cout << -1 << endl;
          return 0;
        } else {
          if (sc[i].first != 2 || i != 1) {
            cout << -1 << endl;
            return 0;
          }
        }
      }
    }
  }
  vector<int> num(N, 0);
  for (const auto& e : sc) {
    num[e.first - 1] = e.second;
  }
  int result = 0;
  for (int i = 0; i < N; i++) {
    result += num[i] * pow(10, (N - 1 - i));
  }
  cout << result << endl;
  return 0;
}
