#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, -1);
  int x, y;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    if (a[x - 1] == -1) {
      a[x - 1] = y;
    } else if (a[x - 1] != y) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (a[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 3) {
    cout << max(a[0], 1) * 100 + max(a[1], 0) * 10 + max(a[2], 0) << endl;
  } else if (n == 2) {
    cout << max(a[0], 1) * 10 + max(a[1], 0) << endl;
  } else {
    cout << max(a[0], 1) << endl;
  }
}
