#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const int N = 2e5 + 5;
const int OO = 1e9 + 7;
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m, idx, num, arr[4] = {10, 10, 10, 10};
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> idx >> num;
    arr[idx] = min(num, arr[idx]);
  }
  int zeros = 0, z = 0;
  for (int i = 1; i <= n; i++) {
    if (arr[i] == 10 && i < n) zeros++;
    if (arr[i] == 0) z++;
  }
  if (zeros > 1 || z + zeros > 1)
    cout << -1;
  else {
    for (int i = 1; i <= n; i++) {
      arr[i] != 10 ? cout << arr[i] : cout << 0;
    }
  }
}
