#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using G = vector<vector<int>>;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  int c[m], s[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  map<int, set<int>> mp;
  for (int i = 0; i < m; i++) {
    if (mp[s[i]].size() == 0) {
      mp[s[i]].insert(c[i]);
    } else {
      if (mp[s[i]].count(c[i]) == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (n != 1) {
    for (int i = 0; i < m; i++) {
      if (s[i] == 1 && c[i] == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int num[n];
  for (int i = 0; i < m; i++) {
    num[s[i] - 1] = c[i];
  }
  for (int i = 0; i < n; i++) {
    cout << num[i];
  }
  cout << endl;
}
