#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 9;
int dig[100];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) dig[i] = -1;
  for (int i = 0, a, b; i < m; i++) {
    cin >> a >> b;
    if (dig[a] != -1 && dig[a] != b) return cout << -1, 0;
    dig[a] = b;
  }
  if (dig[1] == 0 && n > 1) return cout << -1, 0;
  for (int i = 1; i <= n; i++) {
    cout << (dig[i] == -1 ? 0 : dig[i]);
  }
  return 0;
}
