#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const long long INF = 1000000000000000000;
int ans[10];
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < 3; i++) ans[i] = -1;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (ans[s] != -1 && c != ans[s]) {
      cout << -1 << endl;
      return 0;
    }
    if (N != 1 && s == 0 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    ans[s] = c;
  }
  for (int i = 0; i < N; i++) {
    if (ans[i] == -1)
      cout << 0;
    else if (i == 0 && ans[i] == -1)
      cout << 1;
    else
      cout << ans[i];
  }
  cout << endl;
}
