#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int add(int a, int b) {
  int x = a + b;
  if (x >= 1000000007) x -= 1000000007;
  if (x < 0) x += 1000000007;
  return x;
}
long long mul(long long a, long long b) { return (a * b) % 1000000007; }
long long pw(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return ans;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed() {
  long long a = rng();
  return a;
}
pair<int, int> dta[502];
bool ok[10];
int dg(int n) {
  if (n == 0) return 1;
  int x = 0;
  while (n) {
    ++x;
    n /= 10;
  }
  return x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) cin >> dta[i].first >> dta[i].second;
  for (int i = 0; i <= 999; ++i) {
    memset(ok, 0, sizeof(ok));
    if (dg(i) == n) {
      deque<int> d;
      int xx = i;
      while (xx) {
        d.push_front(xx % 10);
        xx /= 10;
      }
      d.push_front(-1);
      int sok = 0;
      for (int x = 1; x < d.size(); ++x) {
        for (int poz = 1; poz <= m; ++poz) {
          if (dta[poz].first == x) {
            if (dta[poz].second == d[x]) {
              sok += 1 - ok[poz];
              ok[poz] = 1;
            }
          }
        }
      }
      if (sok == m) {
        cout << i;
        return 0;
      }
    }
  }
  cout << -1;
  return 0;
}
