#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1000000000000000;
template <class T>
inline bool chmin(T& first, T second) {
  if (first > second) {
    first = second;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& first, T second) {
  if (first < second) {
    first = second;
    return true;
  }
  return false;
}
long long maxx(long long x, long long y, long long z) {
  return max(max(x, y), z);
}
long long minn(long long x, long long y, long long z) {
  return min(min(x, y), z);
}
long long gcd(long long x, long long y) {
  if (x % y == 0)
    return y;
  else
    return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return x * (y / gcd(x, y)); }
long long digsz(long long x) {
  if (x == 0)
    return 1;
  else {
    long long ans = 0;
    while (x) {
      x /= 10;
      ans++;
    }
    return ans;
  }
}
long long digsum(long long x) {
  long long sum = 0;
  while (x) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}
vector<long long> pw2(62, 1);
vector<long long> pw_2(62, 1);
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> ans(N + 1, INF);
  for (long long i = 0; i < (M); i++) {
    long long s, c;
    cin >> s >> c;
    if (ans[s] == INF)
      ans[s] = c;
    else {
      if (ans[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (ans[1] == 0) {
    cout << -1 << endl;
    return 0;
  } else if (ans[1] == INF)
    cout << 1;
  else {
    cout << ans[1];
    for (long long i = (2); i < (N + 1); i++) {
      if (ans[i] == INF)
        cout << 0;
      else
        cout << ans[i];
    }
  }
}
