#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long, long>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
int keta_sum(int num) {
  int dig, sum = 0;
  while (num) {
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}
ll keta_num(ll num) {
  ll total = 0;
  while (num) {
    num /= 10;
    total++;
  }
}
ll binary_search(ll left_key, ll border, ll low, ll high) {
  ll mid = (low + high) / 2;
  while (high > low + 1) {
    mid = (low + high) / 2;
    if (left_key * mid > border)
      high = mid;
    else if (left_key * mid < border)
      low = mid;
    else {
      mid = mid - 1;
      break;
    }
  }
  return mid;
}
bool IsPrime(ll a) {
  ll b = sqrt(a);
  b++;
  while (b-- >= 2) {
    if (a % b == 0) return false;
  }
  return true;
}
ll gcd(ll a, ll b) {
  ll tmp;
  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
ll fibonacchi(ll num) {
  ll f0 = 0, f1 = 1, f2;
  ll count = 0;
  while (count < num) {
    f2 = f0 + f1;
    f0 = f1;
    f1 = f2;
    count++;
  }
  return f2;
}
struct UnionFind {
  vector<int> par;
  UnionFind(int N) : par(N) {
    for (int i = 0; i < N; i++) par[i] = i;
  }
  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
  }
  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};
int main(void) {
  ll N, M, A, B, C, D, E, F, G, K, L, W, H, P, Q, R, V, X, Y;
  string S, T;
  cin >> N >> M;
  ll sc[M][2];
  int cs[3] = {0};
  for (ll i = 0; i < M; i++) {
    cin >> sc[i][0] >> sc[i][1];
    sc[i][0]--;
    cs[sc[i][0]] = sc[i][1];
  }
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < M; j++) {
      if (sc[j][0] == i) {
        if (sc[j][1] != cs[i]) {
          cout << -1 << endl;
          return 0;
        }
        if (i == 0 && sc[j][1] == 0) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
  }
  for (ll i = 0; i < N; i++) {
    if (i == 0 && cs[i] == 0)
      cout << 1 << endl;
    else
      cout << cs[i];
  }
}
