#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n = 0, m = 0;
  cin >> n >> m;
  vector<int> v(n + 1, -1);
  int a = 0, b = 0;
  int found = 0;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (v[a] == -1)
      v[a] = b;
    else {
      if (v[a] != b) found = 1;
    }
  }
  if (v[1] == 0) found = 1;
  if (v[1] == -1) v[1] = 1;
  for (int j = 0; j < v.size(); j++) {
    if (v[j] == -1) {
      v[j] = 0;
    }
  }
  long long ans = 0;
  int count = 0;
  for (int j = v.size() - 1; j >= 1; j--) {
    ans += v[j] * pow(10, count);
    count++;
  }
  if (found)
    cout << "-1" << endl;
  else
    cout << ans << endl;
}
