#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
inline bool minimize(T1& a, T2 b) {
  return b < a && (a = b, 1);
}
template <class T1, class T2>
inline bool maximize(T1& a, T2 b) {
  return a < b && (a = b, 1);
}
template <class T, class V>
istream& operator>>(istream& ist, pair<T, V>& p) {
  return ist >> p.first >> p.second;
}
template <class T>
ostream& operator<<(ostream& ost, pair<T, T>& p) {
  return ost << p.first << ", " << p.second;
}
template <class T>
istream& operator>>(istream& ist, vector<T>& vs) {
  for (auto& e : vs) ist >> e;
  return ist;
}
int const inf = INT_MAX / 2;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> d(3, -1);
  bool bad = 0;
  for (int i = 0; i < (int)M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (d[s] >= 0 && d[s] != c) {
      bad = 1;
    }
    d[s] = c;
  }
  if ((N > 1 && d[0] == 0) || (N > 2 && d[0] == -1 && d[1] == 0)) {
    bad = 1;
  }
  if (bad) {
    cout << "-1\n";
  } else {
    bool f = 0;
    for (int i = 0; i < (int)3; i++) {
      if (d[i] >= 0) {
        f = 1;
        cout << d[i];
      } else if (f) {
        cout << "0";
      }
    }
    if (f == 0) cout << "0";
    cout << "\n";
  }
}
