#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > s(n);
  vector<int> ans(n, 0);
  ans[0] = 1;
  for (int i = 0; i < (n); i++) {
    cin >> s[i].first >> s[i].second;
    s[i].first--;
    ans[s[i].first] = s[i].second;
  }
  bool ok = true;
  for (int i = 0; i < (n); i++) {
    if (ans[s[i].first] != s[i].second) ok = false;
  }
  if (ok) {
    if (n != 1 && ans[0] == 0)
      cout << -1;
    else
      for (int i = 0; i < (n); i++) cout << ans[i];
  } else
    cout << -1;
}
