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