#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; };
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; };
long long mod(long long a, long long b) { return (a + b - 1) / b; };
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
  std::fill((T*)array, (T*)(array + N), val);
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  if (m == 0) {
    if (n == 1) puts("0");
    if (n == 2) puts("10");
    if (n == 3) puts("100");
    return 0;
  }
  string ans = "";
  for (long long(i) = 0; i < (n); i++) ans += "0";
  long long s[m];
  char c[m];
  for (long long(i) = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
    if (ans[s[i]] != '0' && ans[s[i]] != c[i]) {
      cout << "-1" << endl;
      return 0;
    }
    if (s[i] == 0 && c[i] == '0') {
      cout << "-1" << endl;
      return 0;
    }
    ans[s[i]] = c[i];
    if (ans[0] == '0') {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (n > 1 && ans[0] == '0') ans[0] = '1';
  if (n == 1 && m == 0) ans = "0";
  cout << ans << endl;
  return 0;
}
