#include <bits/stdc++.h>
using namespace std;
int N, M;
int ans[10];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  cin >> N >> M;
  memset(ans, -1, sizeof ans);
  for (long long i = 0; i <= long long(M - 1); ++i) {
    int second, c;
    cin >> second >> c;
    if (ans[second] != -1 && ans[second] != c) {
      cout << -1;
      return 0;
    }
    if (second == 1 && c == 0 && N > 1) {
      cout << -1;
      return 0;
    }
    ans[second] = c;
  }
  if (ans[N] == -1) ans[N] = 1;
  for (long long i = 1; i <= long long(N); ++i) {
    if (ans[i] == -1)
      cout << 0;
    else
      cout << ans[i];
  }
}
