#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long N = 15;
long long n, m, a, b, req[5];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  if (n == 1) {
    if (m) {
      cin >> a >> b;
      cout << b;
      return 0;
    } else {
      cout << 0;
      return 0;
    }
  }
  memset(req, -1, sizeof req);
  for (long long i = 0; i < m; i++) {
    cin >> a >> b;
    if (req[a] != -1 and req[a] != b) {
      cout << -1 << '\n';
      return 0;
    }
    if (a == 1 and b == 0) {
      cout << -1 << '\n';
      return 0;
    }
    req[a] = b;
  }
  for (long long i = 1; i <= n; i++) {
    if (i == 1 and req[i] == -1)
      cout << 1;
    else if (req[i] == -1)
      cout << 0;
    else
      cout << req[i];
  }
}
