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