#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(m + 10);
  for (int i = (0); i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    a[i] = make_pair(s, c);
  }
  for (int i = (0); i < (int)(m); i++) {
    if (a[i].first == 1 && a[i].second == 0) {
      if (n > 1) {
        cout << "-1";
        return 0;
      } else {
        cout << "0";
        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;
  if (a[0].first > 1) l += pow(10, n - 1);
  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;
  return 0;
}
