#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> p;
  int min = 0;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (p.count(s)) {
      if (p[s] != c) {
        if (p[s] != c) {
          cout << "-1" << endl;
          return 0;
        }
      }
    } else {
      p[s] = c;
    }
  }
  if (N > 1 && p[1] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (auto q : p) {
    auto k = q.first;
    auto n = q.second;
    min += (int)pow(10, N - k) * n;
  }
  cout << min << endl;
}
