#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m), ans(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
    if (ans[s[i] - 1] == 0) {
      ans[s[i] - 1] = c[i];
    }
    if (ans[s[i] - 1] != c[i]) {
      cout << "-1" << endl;
      return 0;
    }
  }
  for (int i = 0; i < (int)(m); i++) {
    if (ans[0] == 0) {
      cout << "-1" << endl;
      return 0;
    }
    cout << ans[i];
  }
}
