#include <bits/stdc++.h>
using namespace std;
constexpr auto mod = 1000000007;
int ni(int n) {
  if (n == 0) return 1;
  int x = ni(n / 2);
  x *= x;
  if (n % 2 == 1) x *= 2;
  return x;
}
int f(int x, vector<int> s) {
  if (x == 0) return 0;
  if (x == 1) return 1;
  if (s[x] != 0) return s[x];
  s[x] = f(x - 1, s) + f(x - 2, s);
  return s[x];
}
long long int gcd(long long int a, long long int b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long int c(long long int a, long long int b, long long int m) {
  long long int ans = 1;
  for (long long int i = 0; i < b; i++) {
    ans *= a - i;
    ans %= m;
  }
  for (long long int i = 1; i <= b; i++) {
    ans *= modinv(i, m);
    ans %= m;
  }
  return ans;
}
void dfs(int m, int n) {
  stack<string> st;
  st.push("");
  while (!st.empty()) {
    string now = st.top();
    st.pop();
    if (now.size() == n) {
      cout << now << endl;
    } else {
      for (int i = m - 1; i >= 0; i--) {
        string next = now + to_string(i);
        st.push(next);
      }
    }
  }
}
void press(string& v) { v.erase(unique((v).begin(), (v).end()), v.end()); }
int main() {
  int n, m;
  cin >> n >> m;
  vector<char> x(n, '0');
  vector<pair<int, int>> s(m);
  for (int i = (0); i < (m); i++) {
    int a, b;
    cin >> a >> b;
    s[i] = make_pair(a, b);
  }
  for (int i = (0); i < (m); i++) {
    if (x[s[i].first - 1] - '0' == 0 ||
        x[s[i].first - 1] - '0' == s[i].second) {
      x[s[i].first - 1] = s[i].second + '0';
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (x[0] - '0' == 0)
    cout << -1 << endl;
  else {
    for (int i = (0); i < (n); i++) cout << x[i];
    cout << endl;
  }
  return 0;
}
