#include <bits/stdc++.h>
using namespace std;
long long MOD = long long(1e8) + 9;
template <typename T>
T mod(T a, T b) {
  return (a + b) % b;
}
template <typename T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
map<long long, long long> factor(long long n) {
  map<long long, long long> mp;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      mp[i]++;
      n /= i;
    }
  }
  if (n > 1) {
    mp[n]++;
  }
  return mp;
}
void solve() {
  int N, M;
  cin >> N >> M;
  vector<int> num(N, -1);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (num[s] == -1 || num[s] == c) {
      num[s] = c;
    } else {
      cout << "-1" << endl;
      return;
    }
  }
  if (num[0] == 0) {
    if (num.size() == 1) {
      cout << 0 << endl;
      return;
    } else {
      cout << -1 << endl;
      return;
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      if (num[0] == -1)
        cout << 1;
      else
        cout << num[i];
    } else {
      if (num[i] == -1)
        cout << 0;
      else
        cout << num[i];
    }
  }
  cout << endl;
  return;
}
int main(int argc, char const* argv[]) {
  solve();
  return 0;
}
