#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, m, a, b;
  cin >> n >> m;
  std::vector<int> arr(n, -1);
  while (m--) {
    cin >> a >> b;
    a--;
    if (arr[a] >= 0 && arr[a] != b) {
      cout << -1 << endl;
      return 0;
    }
    arr[a] = b;
  }
  if (arr[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (arr[0] == -1) {
    if (n == 1)
      arr[0] = 0;
    else
      arr[0] = 1;
  }
  for (int i = 1; i < n; i++) {
    if (arr[i] == -1) arr[i] = 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = ans * 10 + arr[i];
  }
  cout << ans << endl;
}
