#include <bits/stdc++.h>
using namespace std;
const long long int INF = (long long int)1e18;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, -1);
  for (int i = (0); i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (a[s] == -1) {
      a[s] = c;
    } else if (a[s] != c) {
      cout << -1 << endl;
      exit(0);
    }
  }
  if (a[0] == 0) {
    cout << -1 << endl;
    exit(0);
  } else if (a[0] == -1) {
    a[0] = 1;
  }
  int ans = 0;
  for (int i = (0); i < (n); ++i) {
    ans *= 10;
    if (a[i] == -1) {
    } else {
      ans += a[i];
    }
  }
  cout << ans << endl;
}
