#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(m + 1, -1);
  int s, c;
  for (int i = 1; i <= m; i++) {
    cin >> s >> c;
    if (v[s] != -1 && v[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    v[s] = c;
  }
  for (int i = 1; i <= m; i++) {
    if (v[i] == -1) v[i] = 0;
    for (int j = 2; j <= m - i + 1; j++) {
      v[i] = v[i] * 10;
    }
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) ans += v[i];
  int num = 1;
  for (int i = 2; i <= m; i++) {
    num *= 10;
  }
  if (ans < num) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
