#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll t1, t2, t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x, ll *y) {
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> vec(n, -1);
  bool can = true;
  for (int i = 0; i < m; i++) {
    cin >> t1 >> t2;
    t1--;
    if (vec[t1] == -1) {
      vec[t1] = t2;
    } else if (vec[t1] == t2) {
    } else {
      can = false;
    }
  }
  ll ans = 0;
  if (can) {
    for (int i = 0; i < m; i++) {
      ans *= 10;
      if (vec[i] == -1) {
        if (i != 0) {
          ans += 0;
        } else {
          ans += 1;
        }
      } else {
        ans += vec[i];
      }
    }
    if (ans == 0) {
      ans = -1;
    }
  } else {
    ans = -1;
  }
  cout << ans << endl;
}
