#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  bool ok = true;
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    if (mp.count(s) == 0) mp[s] = c;
    if (mp[s] == c)
      continue;
    else
      ok = false;
  }
  if (!ok || mp[1] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < (n); i++) {
    cout << mp[i + 1];
  }
  printf("\n");
  return 0;
}
