#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<set<int> > rule(n + 1);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    rule[s].insert(c);
  }
  string ans(n, '0');
  bool possible = true;
  for (int i = 1; i <= n; i++) {
    if (rule[i].size() > 1) {
      possible = false;
      break;
    } else if (!rule[i].empty()) {
      ans[i - 1] = '0' + *rule[i].begin();
    }
  }
  bool all0 = true;
  for (char c : ans) {
    all0 &= (c == '0');
  }
  if (n > 1 && all0) {
    possible = false;
  }
  if (n > 1 && ans[0] == '0') {
    ans[0] = '1';
  }
  cout << (possible ? ans : "-1");
  return 0;
}
