#include <bits/stdc++.h>
using namespace std;
int vx[] = {0, 0, -1, 1};
int vy[] = {1, -1, 0, 0};
int dx[] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy[] = {1, 1, 1, 0, 0, -1, -1, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
const long long mod = 1e9 + 7;
const int INF = INT_MAX / 2;
const int N_MAX = 100010;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  int max_digit = -1;
  for (int i = 0; i < int(m); i++) {
    cin >> s[i] >> c[i];
    s[i] = n - s[i] + 1;
    max_digit = max(max_digit, s[i] - 1);
  }
  int log[n];
  for (int i = 0; i < int(n); i++) log[i] = -1;
  for (int i = 0; i < int(m); i++) {
    if (log[s[i] - 1] != -1 && log[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    log[s[i] - 1] = c[i];
  }
  if (n == 1) {
    if (log[0] == -1 || log[0] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < int(m); i++) {
    if (log[s[i] - 1] == 0 && s[i] - 1 == max_digit) {
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < int(n); i++) {
    if (log[i] != -1) ans += log[i] * pow(10, i);
  }
  if (log[n - 1] == -1) ans += 1 * pow(10, n - 1);
  cout << ans << endl;
  return 0;
}
