#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 main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int M;
  cin >> M;
  vector<int> a(N, -1);
  for (long long i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    if (a[s - 1] != -1 && a[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    a[s - 1] = c;
  }
  if (a[0] == 0 && N != 1) {
    cout << -1 << endl;
    return 0;
  }
  if (a[0] == -1) a[0] = 1;
  for (auto i : a) {
    if (i == -1)
      cout << 0;
    else
      cout << i;
  }
  cout << endl;
}
