#include <bits/stdc++.h>
using namespace std;
void solve() {
  int N, M;
  cin >> N >> M;
  int a[N];
  memset(a, -1, sizeof(a));
  bool ans = true;
  for (int i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    if (0 <= a[s - 1] && a[s - 1] != c) {
      ans = false;
      break;
    } else if (1 < N && s == 1 && c == 0) {
      ans = false;
      break;
    } else {
      a[s - 1] = c;
    }
  }
  if (!ans) {
    cout << -1 << endl;
    return;
  }
  for (int i = 0; i < N; ++i) {
    if (a[i] == -1) {
      cout << (i == 0 ? 1 : 0);
    } else
      cout << a[i];
  }
  cout << endl;
}
int main() {
  solve();
  return 0;
}
