#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vint;
typedef vector<double> vdouble;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pair<ll, ll>> vl_l;
typedef vector<pair<int, int>> vi_i;
typedef vector<pair<double, double>> vd_d;
typedef vector<string> vstring;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef pair<double, double> d_d;
template <typename T>
void read(T& x) {
  cin >> x;
}
template <typename T, typename T0>
void read(T& x, T0& y) {
  cin >> x >> y;
}
template <typename T, typename T0, typename T1>
void read(T& x, T0& y, T1& z) {
  cin >> x >> y >> z;
}
template <typename T, typename T0, typename T1, typename T2>
void read(T& x, T0& y, T1& z, T2& w) {
  cin >> x >> y >> z >> w;
}
template <typename T>
void read(vector<T>& oneD, int n) {
  ll n1 = (ll)n;
  for (ll i = 0; i < (n1); i++) {
    ll x;
    read(x);
    oneD.push_back(x);
  }
}
template <typename T>
void read(vector<T>& oneD, ll n) {
  for (ll i = 0; i < (n); i++) {
    ll x;
    read(x);
    oneD.push_back(x);
  }
}
template <typename T>
void read(T oneD[], int n) {
  ll n1 = (ll)n;
  for (ll i = 0; i < (n1); i++) {
    read(oneD[i]);
  }
}
template <typename T>
void read(T oneD[], ll n) {
  for (ll i = 0; i < (n); i++) {
    read(oneD[i]);
  }
}
template <typename T, typename T0>
void read(pair<T, T0>& p) {
  cin >> p.first >> p.second;
}
template <typename T>
void write(T& x) {
  cout << x << endl;
}
template <typename T, typename T0>
void write(T& x, T0& y) {
  cout << x << " " << y << endl;
}
template <typename T, typename T0, typename T1>
void write(T& x, T0& y, T1& z) {
  cout << x << " " << y << " " << z << endl;
}
template <typename T, typename T0, typename T1, typename T2>
void write(T& x, T0& y, T1& z, T2& w) {
  cout << x << " " << y << " " << z << " " << w << endl;
}
template <typename T>
void write(vector<T>& oneD, int n) {
  ll n1 = (ll)n;
  for (ll i = 0; i < (n1); i++) {
    cout << oneD[i] << " ";
  }
  cout << endl;
}
template <typename T>
void write(vector<T>& oneD, ll n) {
  for (ll i = 0; i < (n); i++) {
    cout << oneD[i] << " ";
  }
  cout << endl;
}
template <typename T>
void write(T oneD[], int n) {
  ll n1 = (ll)n;
  for (ll i = 0; i < (n1); i++) {
    write(oneD[i]);
  }
  cout << endl;
}
template <typename T>
void write(T oneD[], ll n) {
  for (ll i = 0; i < (n); i++) {
    write(oneD[i]);
  }
  cout << endl;
}
template <typename T, typename T0>
void write(pair<T, T0>& p) {
  cout << p.first << " " << p.second << " ";
  cout << endl;
}
int main(int argc, char const* argv[]) {
  int n, m;
  read(n, m);
  vint s, c;
  s.resize(m);
  c.resize(m);
  for (int rv = 0; rv < m; rv++) {
    cin >> s[rv] >> c[rv];
  }
  int flag = 0;
  vint ans;
  ans.resize(n);
  for (int i = 0; i < n; i++) {
    ans[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    if (ans[s[i] - 1] != -1 && ans[s[i] - 1] != c[i])
      flag = 1;
    else {
      ans[s[i] - 1] = c[i];
    }
  }
  if (ans[0] == -1)
    ans[0] = 1;
  else {
    for (int i = 0; i < n; i++) {
      if (ans[i] == -1) ans[i] = 0;
    }
  }
  int an = 0;
  int d = 1;
  for (int i = 0; i < n; i++) {
    an += ans[n - i - 1] * d;
    d *= 10;
  }
  if (an == 0 && n != 1) flag = 1;
  int len = to_string(an).size();
  if (len != n) flag = 1;
  if (flag == 1)
    cout << -1 << endl;
  else
    cout << an << endl;
  return 0;
}
