#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    auto it = mp.find(s);
    if (it != mp.end()) {
      if (mp[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    } else
      mp[s] = c;
  }
  for (int i = 1; i <= n; i++) {
    cout << mp[i];
  }
}
