#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using namespace std;
const long long MOD = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int* ans;
  ans = new int[n];
  for (int i = 0; i < n; ++i) {
    ans[i] = -1;
  }
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    if (n != 1 && s == 1 && c == 0) {
      cout << -1 << "\n";
      return 0;
    }
    if (ans[s - 1] != -1 && ans[s - 1] != c) {
      cout << -1 << "\n";
      return 0;
    }
    ans[s - 1] = c;
  }
  int rtv = 0;
  for (int i = 0; i < n; ++i) {
    if (ans[i] != -1) {
      rtv += ans[i];
    }
    rtv *= 10;
  }
  rtv /= 10;
  cout << rtv << "\n";
  return 0;
}
