#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = mod * mod;
const long double eps = 1e-12;
const long double pi = acos(-1.0);
int qp(long long a, long long b, long long mo) {
  int ans = 1;
  do {
    if (b & 1) ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}
int gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
void solve() {
  long long n, m;
  long long s[5], c[5];
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    bool flag = false;
    int num = 0;
    for (int j = 0; j < m; j++) {
      if (i + 1 == s[j]) {
        if (i == 0 && c[j] == 0) {
          ans = -1;
          break;
        }
        if (flag) {
          if (num != c[j]) {
            ans = -1;
            break;
          }
        }
        num = c[j];
        flag = true;
      }
    }
    if (ans == -1) break;
    ans += num * pow(10, (n - i - 1));
  }
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  char nyaa;
  cin >> nyaa;
  return 0;
}
