#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<bool> bo(m + 1);
  vector<int> s(n + 1);
  for (int i = 0; i < (int)(m); i++) {
    int a, b;
    cin >> a >> b;
    if (bo.at(a) == 0) {
      s.at(a) = b;
      bo.at(a) = 1;
    } else if (bo.at(a) == 1 && s.at(a) != b) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (s.at(1) == 0)
    cout << -1;
  else {
    for (int i = 1; i <= m; i++) cout << s.at(i);
  }
  cout << endl;
  return 0;
}
