#include <bits/stdc++.h>
using namespace std;
int int_pow(int, int);
int main() {
  int n, m;
  int *s;
  int *c;
  int *num;
  int ans = 0;
  cin >> n >> m;
  s = new int[m];
  c = new int[m];
  for (int i = 0; i <= m - 1; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i <= m - 2; i++) {
    for (int j = i + 1; j <= m - 1; j++) {
      if (s[i] == s[j]) {
        if (c[i] != c[j]) {
          cout << -1;
          delete[] s;
          delete[] c;
          return 0;
        }
      }
    }
  }
  for (int i = 0; i <= m - 1; i++) {
    if (s[i] > n) {
      cout << -1;
      delete[] s;
      delete[] c;
      return 0;
    }
  }
  num = new int[n];
  for (int i = 0; i <= n - 1; i++) {
    num[i] = 0;
  }
  for (int i = 0; i <= m - 1; i++) {
    num[n - s[i]] = c[i];
  }
  if (num[n - 1] == 0) {
    cout << -1;
    delete[] s;
    delete[] c;
    delete[] num;
    return 0;
  }
  for (int i = 0; i <= n - 1; i++) {
    ans += num[i] * int_pow(10, i);
  }
  cout << ans;
  delete[] s;
  delete[] c;
  delete[] num;
  return 0;
}
int int_pow(int x, int y) {
  int ans = 1;
  for (int i = 0; i <= y - 1; i++) {
    ans *= x;
  }
  return ans;
}
