#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> num(n + 1, -1);
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    if (num[s] == -1) {
      num[s] = c;
      continue;
    }
    if (num[s] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (num[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (num[1] == -1) {
    num[1] = 1;
  }
  int ans = 0;
  for (int u = 1; u < n + 1; u++) {
    if (num[u] == -1) continue;
    ans += num[u] * (int)pow(10, (n - u));
  }
  cout << ans << endl;
}
