#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, q;
  cin >> n >> q;
  int arr[] = {-1, -1, -1};
  bool pos = true;
  for (int i = 0; i < q; ++i) {
    int x, y;
    cin >> x >> y;
    --x;
    if (x == 0) {
      if (y == 0) pos = false;
    }
    if (arr[x] == y || arr[x] == -1) {
      arr[x] = y;
    } else {
      pos = 0;
    }
  }
  if (!pos) {
    cout << -1 << '\n';
  } else {
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      if (arr[i] == -1) arr[i] = 1;
      ans += arr[i];
      ans *= 10;
    }
    ans /= 10;
    cout << ans << '\n';
  }
  return 0;
}
