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