#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 0;
  int hoge[5] = {};
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (hoge[a - 1] == 0 || hoge[a - 1] == b) {
      hoge[a - 1] = b;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (hoge[n - 1] == 0 && n > 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < 5; i++) {
    ans += hoge[4 - i] * pow(10, i);
  }
  cout << ans / pow(10, n - 1) << endl;
}
