#include <bits/stdc++.h>
using namespace std;
const int N = 4, M = 6;
int n, m, s, c, num[N];
void solve() {
  cin >> n >> m;
  fill(num, num + n + 1, -1);
  for (int i = 0; i < m; ++i) {
    cin >> s >> c;
    if (s > n) {
      cout << -1;
      return;
    }
    if (num[s] != -1 && num[s] != c) {
      cout << -1;
      return;
    }
    num[s] = c;
  }
  if (n > 1 && num[1] == 0) {
    cout << -1;
    return;
  }
  for (int i = 1; i <= n; ++i) {
    if (num[i] != -1)
      cout << num[i];
    else
      cout << 0;
  }
}
int main() {
  solve();
  return 0;
}
