#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
T gcd(T a, T b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
template <class T>
T lcm(T a, T b) {
  return (a * b) / gcd(a, b);
}
int INF = 1e9 + 7;
vector<int> dx = {-1, 0, 1, 0};
vector<int> dy = {0, -1, 0, 1};
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> c(n, -1);
  int ans = 0;
  for (int i = 0; i < (int)(m); i++) {
    int s, k;
    cin >> s >> k;
    s--;
    if (c[s] == -1)
      c[s] = k;
    else {
      if (c[s] == k)
        continue;
      else {
        ans = -1;
      }
    }
  }
  if (ans == -1) {
    cout << ans << endl;
    return 0;
  }
  for (int i = 0; i < (int)(n); i++) {
    if (c[i] == -1 && i == 0) ans += 1 * pow(10, n - 1 - i);
    if (c[i] == -1)
      continue;
    else {
      ans += c[i] * pow(10, n - 1 - i);
    }
  }
  if (c[0] == 0) {
    ans = -1;
  }
  cout << ans << endl;
}
