#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int a[5];
pair<int, int> sc[7];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  if (!m) {
    if (n == 1)
      cout << 0;
    else
      cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; ++i) a[i] = 1e9;
  for (int i = 1; i <= m; ++i) cin >> sc[i].first >> sc[i].second;
  for (int i = 1; i <= m; ++i)
    a[sc[i].first] = min(a[sc[i].first], sc[i].second);
  if (a[1] == 1e9 || !a[1]) cout << -1, exit(0);
  for (int i = 2; i <= n; ++i)
    if (a[i] == 1e9) a[i] = 0;
  for (int i = 1; i <= n; ++i) cout << a[i];
  return 0;
}
