#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using li = list<int>;
using lil = list<ll>;
using lis = list<string>;
using fli = forward_list<int>;
using fll = forward_list<ll>;
using fls = forward_list<string>;
using si = stack<int>;
using sl = stack<ll>;
using ss = stack<string>;
using qi = queue<int>;
using ql = queue<ll>;
using qs = queue<string>;
using pqi = priority_queue<int>;
using pql = priority_queue<ll>;
using pqs = priority_queue<string>;
using dqi = deque<int>;
using dql = deque<ll>;
using dqs = deque<string>;
template <typename T, typename U>
void Inparray(T &f, U n) {
  for (int i = 0; i < n; i++) cin >> f[i];
}
template <typename T, typename U>
void Printarray(T f, U n) {
  for (int i = 0; i < n; i++) i != n ? cout << f[i] : cout << f[i] << endl;
}
template <typename T, typename U>
void Printarray2(T f, U n) {
  for (int i = 0; i < n; i++) cout << f[i] << endl;
}
template <typename T, typename U, typename V>
void Printarray3(T f, U a, V b) {
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      cout << f[i][j];
    }
    cout << endl;
  }
}
template <typename T, typename U>
void Printarray4(T f, U n) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << f[i][j];
    }
    cout << endl;
  }
}
void flagfunc(bool flag, string A, string B) {
  flag ? cout << A << endl : cout << B << endl;
}
void flag2func(bool flag) {
  flag ? cout << "Yes" << endl : cout << "No" << endl;
}
void flag3func(bool flag) {
  flag ? cout << "YES" << endl : cout << "NO" << endl;
}
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n, m;
  cin >> n >> m;
  int s, c;
  vector<int> a(n, -1);
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (!(s == 1 && c == 0) && (a[s - 1] == -1 || a[s - 1] == c)) {
      a[s - 1] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) a[i] != -1 ? cout << a[i] : cout << 0;
  cout << endl;
}
