#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
using M = map<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  M mp;
  for (int i = 0; i < (int)(n); i++) mp[i + 1] = 0;
  int ans = 0;
  int b = 1;
  for (int i = 0; i < (int)(m); i++) {
    int x, y;
    cin >> x >> y;
    if (mp[x] == 0) mp[x] = y;
    if (mp[x] != y) b = 0;
  }
  int z = 1;
  if (b) {
    for (int i = 0; i < (int)(n); i++) {
      if (z && mp[i + 1] < 1) {
        ans = -1;
        break;
      } else {
        z = 0;
        ans *= 10;
        ans += mp[i + 1];
      }
    }
    cout << ans << endl;
  } else
    cout << -1 << endl;
  return 0;
}
