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