#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.14159265358979323846264;
template <typename... T>
void read(T&... args) {
  ((cin >> args), ...);
}
template <typename... T>
void write(T&&... args) {
  ((cout << args << " "), ...);
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
void fio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void solve() {
  long long n = 0;
  read(n);
  string st(n, '0');
  long long m;
  cin >> m;
  while (m--) {
    long long a, b;
    read(a, b);
    char bb = '0' + b;
    if (a == 1 && b == 0) {
      cout << -1 << endl;
      return;
    } else if (st[a - 1] != '0' && st[a - 1] != bb) {
      cout << -1 << endl;
      return;
    } else if (st[a - 1] == '0') {
      st[a - 1] = bb;
    }
  }
  cout << st;
}
int32_t main() {
  fio();
  return solve(), 0;
}
