#include <bits/stdc++.h>
using namespace std;
inline long long int in() {
  long long int x;
  cin >> x;
  return x;
}
template <typename tuple<int, int, int> >
inline istream& operator>>(istream& i, vector<tuple<int, int, int> >& v) {
  for (long long int j = (0); j < (((int)(v).size())); ++j) i >> v[j];
  return i;
}
template <typename tuple<int, int, int> >
string join(const vector<tuple<int, int, int> >& v) {
  stringstream s;
  for (long long int i = (0); i < (((int)(v).size())); ++i) s << ' ' << v[i];
  return s.str().substr(1);
}
template <typename tuple<int, int, int> >
inline ostream& operator<<(ostream& o, const vector<tuple<int, int, int> >& v) {
  if ((int)(v).size()) o << join(v);
  return o;
}
template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}
template <typename T1, typename T2>
inline ostream& operator<<(ostream& o, const pair<T1, T2>& v) {
  return o << v.first << "," << v.second;
}
template <typename tuple<int, int, int> >
inline long long int suma(const vector<tuple<int, int, int> >& a) {
  long long int res(0);
  for (auto&& x : a) res += x;
  return res;
}
const double eps = 1e-10;
const long long int LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
const int MOD = 1000000007;
struct mint {
  long long int x;
  mint(long long int x = 0) : x(x % MOD) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint operator++() { return *this = mint(x + 1); }
  mint operator--() { return *this = mint(x - 1); }
};
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
map<long long int, long long int> prime_factor(long long int n) {
  map<long long int, long long int> ret;
  for (long long int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
const int MAX = 1001001;
long long int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long int nCr(int n, int k) {
  if (n < k || n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct Edge {
  int to, id;
};
vector<vector<Edge> > e;
vector<int> cc;
void dfs(int v, int color = -1, int from = -1) {
  int cnt = 1;
  for (long long int i = (0); i < ((e[v].size())); ++i) {
    int eid = e[v][i].id;
    if (e[v][i].to == from) continue;
    if (cnt == color) ++cnt;
    cc[eid] = cnt;
    ++cnt;
    dfs(e[v][i].to, cc[eid], v);
  }
}
bool is_prime(long long int x) {
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return false;
  return true;
}
int main() {
  long long int n = in();
  long long int m = in();
  vector<long long int> s(4, -1);
  bool judge = false;
  for (long long int i = (0); i < ((m)); ++i) {
    long long int si = in() - 1, ci = in();
    if (s[si] == -1) {
      s[si] = ci;
    } else if (s[si] == ci) {
    } else {
      judge = true;
    }
  }
  if (judge) {
    cout << -1 << endl;
  } else if (s[0] == 0) {
    cout << -1 << endl;
  } else {
    for (long long int i = (0); i < ((n)); ++i) {
      if (s[i] == -1) {
        if (i == 0)
          cout << 1;
        else
          cout << 0;
      } else {
        cout << s[i];
      }
    }
    cout << endl;
  }
  return 0;
}
