#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  if (n == 1 && m == 0) {
    cout << 0 << "\n";
    return 0;
  }
  string num(n, '0');
  bool ok = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    --s;
    if (num[s] == '0' || num[s] == ('0' + c))
      num[s] = '0' + c;
    else {
      ok = false;
      break;
    }
  }
  cout << (num[0] != '0' ? num : "-1") << "\n";
}
