#include <bits/stdc++.h>
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double>;
using vvd = std::vector<vd>;
using qi = std::queue<int>;
using vpii = std::vector<std::pair<int, int> >;
using vpll = std::vector<pll>;
using namespace std;
const int Mod = (1e9) + 7;
const int INF = 1e9 + 19;
const ll INFL = 1e18 + 19;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
template <class T1, class T2>
inline void chmin(T1& a, T2 b) {
  if (a > b) a = b;
}
template <class T1, class T2>
inline void chmax(T1& a, T2 b) {
  if (a < b) a = b;
}
template <class T>
inline void pri(T a) {
  cout << a << endl;
}
template <class T1, class T2>
void update(T1& a, T2 b) {
  a += b;
  if (a > Mod) a %= Mod;
}
inline void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest) {
  cin >> first;
  IN(rest...);
  return;
}
inline void OUT(void) {
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void OUT(First first, Rest... rest) {
  cout << first << " ";
  OUT(rest...);
  return;
}
bool pairsort(pll pl, pll pr) {
  if (pl.first == pr.first) return pl.second > pr.second;
  return pl.first < pr.first;
}
int cntbit(ll a, int n, int j) {
  int res = 0;
  for (int(i) = (j); (i) < (n); (i)++) {
    if (a >> i & 1) {
      res++;
    }
  }
  return res;
}
ll makebit(ll a, int n, int j) {
  ll res = 0;
  for (int(i) = (j); (i) < (n); (i)++) {
    if (a & (1 << i)) res |= 1ll << (i - j);
  }
  return res;
}
int compress(vi& x1, vi& x2, int w) {
  int n = x1.size();
  vi vx;
  for (int(i) = 0; (i) < (n); (i)++) {
    vx.push_back(x1[i]);
    vx.push_back(x2[i]);
  }
  vx.push_back(0);
  vx.push_back(w);
  sort((vx).begin(), (vx).end());
  vx.erase(unique((vx).begin(), (vx).end()), vx.end());
  for (int(i) = 0; (i) < (n); (i)++) {
    int idx1 = lower_bound((vx).begin(), (vx).end(), x1[i]) - vx.begin();
    int idx2 = lower_bound((vx).begin(), (vx).end(), x2[i]) - vx.begin();
    x1[i] = idx1;
    x2[i] = idx2;
  }
  return vx.size() - 1;
}
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
int n, m, k;
vvi dp;
string S;
vll cost(1 << 16);
int a, b, c;
int h, w;
vi v;
vll u;
vpii vp;
bool check() {}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  IN(n, m);
  vi x(n, 0);
  for (int(i) = 0; (i) < (m); (i)++) {
    int a, b;
    IN(a, b);
    a--;
    if (x[a] != 0 && x[a] != b) {
      OUT(-1);
      return 0;
    }
    if (a == 0 && b == 0) {
      OUT(-1);
      return 0;
    }
    x[a] = b;
  }
  vi tens(n + 1);
  tens[0] = 1;
  for (int(i) = 0; (i) < (n); (i)++) {
    tens[i + 1] = tens[i] * 10;
  }
  if (x[0] == 0) x[0] = 1;
  int ans = 0;
  for (int(i) = 0; (i) < (n); (i)++) {
    ans += x[i] * tens[n - 1 - i];
  }
  cout << ans << endl;
  return 0;
}
