#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> sc(m);
  for (int i = (0); i < (m); ++i) cin >> sc[i].first >> sc[i].second;
  sort((sc).begin(), (sc).end());
  int num = -1;
  int keta = -1;
  int ans = 0;
  int count = 0;
  if (n == 1) {
    int now = sc[0].second;
    for (int i = (0); i < (m); ++i) {
      if (now == sc[i].second) {
      } else {
        puts("-1");
        return 0;
      }
    }
    cout << now << endl;
    return 0;
  }
  for (int i = (0); i < (m); ++i) {
    if (n == 1 && m == 1 && sc[i].first == 1 && sc[i].second == 0) {
      puts("0");
      return 0;
    }
    if (sc[i].first == keta && sc[i].second != num) {
      puts("-1");
      return 0;
    }
    if (sc[i].first == keta) continue;
    if (sc[i].first == 1 && sc[i].second == 0) {
      puts("-1");
      return 0;
    }
    num = sc[i].second;
    keta = sc[i].first;
    ans += pow(10, n - keta) * num;
  }
  if (n == 2) {
    if (ans < 10) {
      ans += 10;
    }
  }
  if (n == 3) {
    if (ans < 100) {
      ans += 100;
    }
  }
  cout << ans << endl;
}
