#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  map<int, int> memo;
  map<int, bool> judge;
  bool ansjudge = 1;
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    if (judge[s] && memo[s] != c)
      ansjudge = 0;
    else {
      memo[s] = c;
      judge[s] = 1;
    }
  }
  if (!ansjudge)
    cout << -1 << endl;
  else if (memo[1] == 0)
    cout << -1 << endl;
  else
    for (int i = 0; i < (int)(n); i++) cout << memo[i + 1];
}
