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