#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m, w;
  int num;
  cin >> n >> m;
  vector<int> a(n), b(n);
  for (int i = 0; i < m; i++) {
    cin >> w >> num;
    if (b[w - 1] == 0 || a[w - 1] == num) {
      a[w - 1] = num;
      b[w - 1] = 1;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (a[0] == 0 && n != 1) {
    cout << -1 << endl;
    return 0;
  }
  for (auto c : a) cout << c;
  cout << endl;
}
