#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y;
  string s;
  cin >> n >> m;
  for (int i = 0; i < (int)(n); i++) s += '0';
  for (int i = 0; i < (int)(m); i++) {
    cin >> x >> y;
    if (s[x - 1] != '0' && s[x - 1] != y + '0') {
      cout << -1;
      return 0;
    } else
      s[x - 1] = y + '0';
  }
  if (s.size() > 1 && s[0] == '0') {
    cout << -1;
    return 0;
  }
  cout << s;
}
