#include <bits/stdc++.h>
using namespace std;
const int N = 500002;
const int mod = 1000000007;
const long long int inf = INT64_MAX;
const long double pi = 3.14159265359;
void fastIO(void);
void decimal(int);
int modmulti(int, int);
int modadd(int, int);
int modpower(int, int);
int gcd(int, int);
int modinv(int);
int main() {
  fastIO();
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > v(m);
  for (int i = 0; i < m; i++) {
    cin >> v[i].first >> v[i].second;
  }
  vector<int> ans(n);
  int f = 0;
  for (int i = 0; i < n; i++) ans[i] = -1;
  for (int i = 0; i < m; i++) {
    if (ans[v[i].first - 1] == -1 || ans[v[i].first - 1] == v[i].second) {
      ans[v[i].first - 1] = v[i].second;
    } else {
      f = 1;
      break;
    }
  }
  if (f) {
    cout << -1 << "\n";
    return 0;
  }
  if (n == 1) {
    if (ans[0] == -1)
      cout << 0 << "\n";
    else
      cout << ans[0] << "\n";
    return 0;
  }
  if (n == 2) {
    if (ans[0] == 0) {
      cout << -1 << "\n";
      return 0;
    }
    if (ans[0] == -1)
      cout << 1;
    else
      cout << ans[0];
    if (ans[1] == -1)
      cout << 0;
    else
      cout << ans[0];
    cout << "\n";
    return 0;
  }
  if (n == 3) {
    if (ans[0] == 0) {
      cout << -1 << "\n";
      return 0;
    }
    if (ans[0] == -1)
      cout << 1;
    else
      cout << ans[0];
    if (ans[1] == -1)
      cout << 0;
    else
      cout << ans[0];
    if (ans[2] == -1)
      cout << 0;
    else
      cout << ans[2];
    cout << "\n";
    return 0;
  }
}
void fastIO(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void decimal(int n) {
  cout << fixed;
  cout << setprecision(n);
}
int modmulti(int a, int b) { return ((a % mod) * 1ll * (b % mod)) % mod; }
int modadd(int a, int b) {
  int asdfgh = ((a % mod) + (b % mod) + mod + mod) % mod;
  asdfgh = (asdfgh + mod) % mod;
  return asdfgh;
}
int modpower(int a, int n) {
  if (n == 0) return 1;
  if (n == 1) return a % mod;
  int b = modpower(a, n / 2);
  b = modmulti(b, b);
  if (n % 2 == 0) return b;
  return modmulti(a, b);
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int modinv(int a) { return modpower(a, mod - 2); }
