#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();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  pair<int, int> p[M];
  map<int, int> mp;
  bool exist = true;
  for (int i = 0; i < M; ++i) {
    cin >> s[i] >> c[i];
    p[i] = make_pair(s[i], c[i]);
  }
  string S[N], T;
  sort(p, p + M);
  for (int i = 0; i < M - 1; ++i) {
    if (p[i].first == p[i + 1].first) {
      if (p[i].second != p[i + 1].second) {
        exist = false;
      }
    }
  }
  int tmp = 0;
  int res = 0;
  int ans = 0;
  if (exist) {
    for (int i = 0; i < N; ++i) {
      S[i] = '0';
    }
    for (int i = 0; i < M; ++i) {
      S[p[i].first - 1] = toString(p[i].second);
    }
    for (int i = 0; i < N; ++i) {
      T += S[i];
    }
    ans = toInt(T);
    string R = toString(ans);
    if (R.length() == N) {
      cout << R;
    } else {
      cout << -1;
    }
  } else {
    cout << -1;
  }
}
