#include <bits/stdc++.h>
using namespace std;
const int N = 7;
int n, m;
int dig[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < N; i++) {
    dig[i] = -1;
  }
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    if (a > n) {
      cout << -1 << '\n';
      return 0;
    }
    if (dig[a] == -1)
      dig[a] = b;
    else if (dig[a] != b) {
      cout << -1 << '\n';
      return 0;
    }
  }
  if (dig[1] <= 0) {
    if (n > 1) {
      cout << -1 << '\n';
    } else {
      cout << 0 << '\n';
    }
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    cout << max(dig[i], 0);
  }
  cout << '\n';
  return 0;
}
