#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int abs_A(int num) {
  if (num > 0)
    return num;
  else
    return -num;
}
int abs_B(long long num, long long numb) {
  if (num - numb >= 0)
    return num - numb;
  else
    return -1 * (num - numb);
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
bool permutation(vector<int>& vec, vector<int>& P) {
  bool ok = true;
  for (int i = 0; i < vec.size(); i++) {
    if (vec.at(i) != P.at(i)) {
      ok = false;
    }
  }
  return ok;
}
const long long MOD = 1000000007;
const int INF = 1001001001;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ans(N, 0);
  vector<bool> C(N, false);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (C.at(a - 1) == true && b != ans.at(a - 1)) {
      cout << "-1" << endl;
      return 0;
    }
    C.at(a - 1) = true;
    ans.at(a - 1) = b;
  }
  if (ans.at(0) == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    cout << ans.at(i);
  }
  cout << endl;
}
