#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, si, ci;
  cin >> n >> m;
  int num[n];
  memset(num, 1, sizeof(num));
  map<int, int> s;
  for (int i = 0; i < m; i++) {
    cin >> si >> ci;
    if (si == 1 && ci == 0 && n != 1) {
      cout << "-1\n";
      return 0;
    } else if (s.find(si) != s.end() && s[si] != ci) {
      cout << "-1\n";
      return 0;
    } else {
      num[si - 1] = ci;
      s[si] = ci;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << num[i];
  }
  cout << '\n';
}
