#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, 10);
  int tf = 0;
  for (size_t i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (a[s] == 10 || a[s] == c) {
      a[s] = c;
    } else {
      tf = 1;
    }
  }
  int ans = 0;
  if (tf == 0) {
    for (size_t i = 0; i < n; i++) {
      ans *= 10;
      ans += (a[i] % 10);
    }
  } else {
    ans = -1;
  }
  int min = 1;
  for (size_t i = 0; i < n - 1; i++) {
    min *= 10;
  }
  if (ans < min) {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}
