#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> a;
vector<int> track;
void solve(int arr1[], int arr2[]) {
  for (int i = 0; i < m; i++) {
    if (a[arr1[i] - 1] == 0 ||
        (a[arr1[i] - 1] == arr2[i] && track[arr1[i] - 1] != 0)) {
      a[arr1[i] - 1] = arr2[i];
      track[arr1[i] - 1]++;
    } else {
      cout << -1;
      return;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << a[i];
  }
}
int main() {
  cin >> n >> m;
  int arr1[m], arr2[m];
  for (int i = 0; i < n; i++) {
    a.push_back(0);
    track.push_back(0);
  }
  for (int i = 0; i < m; i++) {
    cin >> arr1[i] >> arr2[i];
  }
  solve(arr1, arr2);
  return 0;
}
