#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
int main(void) {
  int n, m;
  cin >> n >> m;
  int s[m];
  int c[m];
  int ans[n];
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < (n); i++) {
    ans[i] = 999;
  }
  for (int i = 0; i < (m); i++) {
    if (ans[s[i] - 1] != c[i] and ans[s[i] - 1] != 999) {
      cout << -1;
      return 0;
    }
    ans[s[i] - 1] = c[i];
  }
  if (n > 1 and ans[0] == 0) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < (n); i++) {
    if (ans[i] == 999 and i == 0) {
      continue;
    }
    if (ans[i] == 999) {
      cout << 0;
      continue;
    }
    cout << ans[i];
  }
  return 0;
}
