#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 10;
int arr[5], n, m, c, tmp;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  memset(arr, -1, sizeof arr);
  for (int i = 0; i < m; ++i) {
    cin >> c >> tmp;
    if (arr[c] == -1)
      arr[c] = tmp;
    else if (arr[c] != tmp) {
      cout << "-1";
      return 0;
    }
  }
  if (arr[1] == -1) arr[1] = 1;
  if (arr[1] == 0 && n > 1) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    if (arr[i] == -1)
      cout << 0;
    else
      cout << arr[i];
  }
  return 0;
}
