#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(m);
  for (int i = (0); i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      cout << "-1";
      return 0;
    }
    a[i] = make_pair(s, c);
  }
  for (int i = (0); i < (int)(m); i++) {
    if (a[i].first == 1 && a[i].second == 0) {
      cout << "-1";
      return 0;
    }
  }
  sort(a.begin(), a.end());
  for (int i = (0); i < (int)(m - 1); i++) {
    if (a[i].first == a[i + 1].first && a[i].second != a[i + 1].second) {
      cout << "-1";
      return 0;
    }
  }
  int l = 0;
  l += pow(10, (n - a[0].first)) * a[0].second;
  for (int i = (1); i < (int)(m); i++) {
    if (a[i].first != a[i - 1].first)
      l += pow(10, (n - a[i].first)) * a[i].second;
  }
  cout << l;
}
