#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
const int IINF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const string MM = " ";
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n, 0);
  for (size_t i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (v[s - 1] != 0) {
      if (v[s - 1] == c) {
        continue;
      } else {
        cout << -1 << "\n";
        return 0;
      }
    } else {
      v[s - 1] = c;
    }
  }
  if (v[0] == 0) {
    cout << -1 << "\n";
    return 0;
  }
  for (size_t i = 0; i < n; i++) {
    cout << v[i];
  }
  cout << "\n";
}
