#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> ret(N, -1);
  for (int _ = (0); _ < (M); ++_) {
    int s, c;
    cin >> s >> c;
    s--;
    if (ret[s] < 0)
      ret[s] = c;
    else if (ret[s] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = (0); i < (N); ++i)
    if (ret[i] < 0) ret[i] = 0;
  if (1 < N && ret[0] == 0) {
    cout << -1 << endl;
  } else {
    for (int i = (0); i < (N); ++i) cout << ret[i];
    cout << endl;
  }
  return 0;
}
