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