#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = long long(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
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; }
int n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  vector<int> a(n, -1);
  for (int i = 0; i < m; i++) {
    int temp, temp1;
    cin >> temp >> temp1;
    temp--;
    if (a[temp] == -1) {
      a[temp] = temp1;
    } else {
      if (a[temp] != temp1) return cout << -1 << "\n", 0;
    }
  }
  long long ans = 0;
  long long keta = 1;
  for (int i = n - 1; i >= 0; i--) {
    if (i == 0) {
      if (a[i] != -1) {
        ans += a[i] * keta;
      } else {
        ans += keta;
      }
    } else {
      if (a[i] != -1) {
        ans += a[i] * keta;
      } else {
      }
      keta *= 10;
    }
  }
  long long ans1 = ans;
  int count = 0;
  while (ans1) {
    ans1 /= 10;
    count++;
  }
  if (n != count) return cout << -1 << "\n", 0;
  if (ans == 0 && n != 1) return cout << -1 << "\n", 0;
  cout << ans << "\n";
}
