#include <bits/stdc++.h>
using namespace std;
bool SortbySecDesc(const pair<long long, long long> &a,
                   const pair<long long, long long> &b) {
  return a.second > b.second;
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  ;
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  int a[10];
  memset(a, -1, sizeof(a));
  for (int i = 0; i < m; i++) {
    int indx = v[i].first;
    if (a[indx] == -1) {
      a[indx] = v[i].second;
    }
  }
  if (a[1] == -1 || a[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] != -1) count++;
  }
  if (count == n) {
    for (int i = 1; i <= n; i++) cout << a[i];
    return 0;
  } else {
    if (n == 1) {
      cout << 0 << endl;
      return 0;
    } else {
      for (int i = 1; i <= n; i++) {
        if (a[i] == -1 && i > 1) {
          a[i] = 0;
        }
      }
      for (int i = 1; i <= n; i++) {
        if (a[i] == -1 && i == 1)
          continue;
        else
          cout << a[i];
      }
      return 0;
    }
  }
  return 0;
}
