#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main() {
  int n, m, i;
  cin >> n >> m;
  vector<pair<int, int> > sc(n);
  vector<int> keta(n, 0);
  for (int i = 0; i < m; i++) {
    cin >> sc[i].first >> sc[i].second;
    if (sc[i].first == 1 && sc[i].second == 0) {
      cout << -1;
      return 0;
    } else if (keta[sc[i].first - 1] == 0 ||
               keta[sc[i].first - 1] == sc[i].second) {
      keta[sc[i].first - 1] = sc[i].second;
    } else {
      cout << -1;
      return 0;
    }
  }
  int ans = 0;
  if (keta[0] != 0) {
    for (int i = 0; i < n; i++) {
      ans += pow(10, n - i - 1) * keta[i];
    }
    cout << ans;
  } else {
    ans += pow(10, n - 1);
    for (int i = 0; i < n - 1; i++) {
      ans += pow(10, n - i - 2) * keta[i + 1];
    }
    cout << ans;
  }
  return 0;
}
