#include <cstdio>           // scanf(), getc(), ungetc()
#include <cstdlib>          // abs()
#include <string>
#include <queue>
#include <map>
#include <algorithm>        // swap()
#include <iostream>         // cin, cout, cerr, endl

using namespace std;
static const int N = 8;
static const int NX = 4;
static const int NY = 2;

struct puzzle
{
	char f[N];
	int space;
	string path;

	bool operator < (const puzzle &p) const
	{
		for (int i = 0; i < N; ++i)
		{
			if (f[i] != p.f[i])
				return f[i] > p.f[i];
		}

		return false;
	}
};

int lineno;

bool
is_done(puzzle p)
{
	for (int i = 0; i < N; ++i)
	{
		if (p.f[i] != i)
			return false;
	}

	return true;
}

static const int dx[4] = { 0,-1, 0, 1};
static const int dy[4] = {-1, 0, 1, 0};
static const char dir[4] = {'U', 'L', 'D', 'R'};

string
bfs(puzzle s)
{
	queue<puzzle> Q;
	map<puzzle, bool> V;

	s.path = "";
	V[s] = true;
	Q.push(s);
	while (!Q.empty())
	{
		puzzle u = Q.front(); Q.pop();
		if (is_done(u))
			return u.path;

		int x0 = u.space % NX, y0 = u.space / NX;
		for (int r = 0; r < 4; ++r)
		{
			int nx = x0 + dx[r], ny = y0 + dy[r];
			if (0 <= nx && nx < NX && 0 <= ny && ny < NY)
			{
				puzzle v = u;
				v.space = ny * NX + nx;
				swap(v.f[u.space], v.f[v.space]);
				if (!V[v])
				{
					V[v] = true;
					v.path += dir[r];
					Q.push(v);
				}
			}
		}
	}

	return "unsolvable";
}

bool
ope_line()
{
	puzzle in;

	lineno++;
	int c = getc(stdin);
	if (c == EOF)
		return false;

	ungetc(c, stdin);
	for (int i = 0; i < N; ++i)
	{
		int j;
		scanf("%d", &j);
		in.f[i] = j;
		if (j == 0)
			in.space = i;
	}

	cout << bfs(in).size() << endl;

	c = getc(stdin);
	if (c == EOF)
		return false;

	return true;
}

int
main(int argc, char **argv)
{
	lineno = 0;
	while (ope_line())
		;

	return 0;
}