#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n, 0);
  bool j = true;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    if (a == 0 && b == 0) j = false;
    if (v[a] == b && j || v[a] == 0 && j)
      v[a] = b;
    else {
      cout << "-1" << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; ++i) cout << v[i];
  cout << endl;
}
